From db8c109817c9f02b34bef33e3eb7403fb17a6fd6 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 19 Sep 2017 14:16:32 -0700 Subject: [PATCH] Client::poll_ready() returns an Error if next stream ID would overflow (#103) Closes #102 --- src/client.rs | 2 +- src/proto/connection.rs | 2 +- src/proto/streams/send.rs | 6 +++++- src/proto/streams/streams.rs | 6 ++++-- tests/client_request.rs | 7 ++++++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/client.rs b/src/client.rs index 1a185a9..cee5f99 100644 --- a/src/client.rs +++ b/src/client.rs @@ -91,7 +91,7 @@ where /// Returns `Ready` when the connection can initialize a new HTTP 2.0 /// stream. pub fn poll_ready(&mut self) -> Poll<(), ::Error> { - Ok(self.connection.poll_send_request_ready()) + self.connection.poll_send_request_ready() } /// Send a request on a new HTTP 2.0 stream diff --git a/src/proto/connection.rs b/src/proto/connection.rs index f871f5e..23d48ef 100644 --- a/src/proto/connection.rs +++ b/src/proto/connection.rs @@ -250,7 +250,7 @@ where B: IntoBuf, { /// Returns `Ready` when new the connection is able to support a new request stream. - pub fn poll_send_request_ready(&mut self) -> Async<()> { + pub fn poll_send_request_ready(&mut self) -> Poll<(), ::Error> { self.streams.poll_send_request_ready() } diff --git a/src/proto/streams/send.rs b/src/proto/streams/send.rs index b8053bb..114c43d 100644 --- a/src/proto/streams/send.rs +++ b/src/proto/streams/send.rs @@ -299,6 +299,10 @@ where Ok(()) } + pub fn ensure_next_stream_id(&self) -> Result { + self.next_stream_id.map_err(|_| OverflowedStreamId) + } + /// Returns a new StreamId if the local actor can initiate a new stream. fn try_open(&self) -> Result { if P::is_server() { @@ -306,6 +310,6 @@ where return Err(UnexpectedFrameType); } - self.next_stream_id.map_err(|_| OverflowedStreamId) + self.ensure_next_stream_id() } } diff --git a/src/proto/streams/streams.rs b/src/proto/streams/streams.rs index 717de81..c199ea5 100644 --- a/src/proto/streams/streams.rs +++ b/src/proto/streams/streams.rs @@ -403,11 +403,13 @@ impl Streams where B: Buf, { - pub fn poll_send_request_ready(&mut self) -> Async<()> { + pub fn poll_send_request_ready(&mut self) -> Poll<(), ::Error> { let mut me = self.inner.lock().unwrap(); let me = &mut *me; - me.counts.poll_open_ready() + me.actions.send.ensure_next_stream_id()?; + + Ok(me.counts.poll_open_ready()) } } diff --git a/tests/client_request.rs b/tests/client_request.rs index 4f3b952..ec4c721 100644 --- a/tests/client_request.rs +++ b/tests/client_request.rs @@ -85,7 +85,12 @@ fn request_stream_id_overflows() { .body(()) .unwrap(); - // second cant use the next stream id, it's over + + // second cannot use the next stream id, it's over + + let poll_err = h2.poll_ready().unwrap_err(); + assert_eq!(poll_err.to_string(), "user error: stream ID overflowed"); + let err = h2.send_request(request, true).unwrap_err(); assert_eq!(err.to_string(), "user error: stream ID overflowed");