From dca336f8b2fa76dfe951779775ab10ecd2a66353 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Fri, 6 Apr 2018 15:51:34 -0700 Subject: [PATCH] send proper max stream ID in graceful goaway (#254) --- src/frame/stream_id.rs | 2 -- src/proto/connection.rs | 4 ++-- src/proto/go_away.rs | 2 +- tests/server.rs | 5 ++++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/frame/stream_id.rs b/src/frame/stream_id.rs index 17ae597..7406e70 100644 --- a/src/frame/stream_id.rs +++ b/src/frame/stream_id.rs @@ -14,8 +14,6 @@ impl StreamId { pub const MAX: StreamId = StreamId(u32::MAX >> 1); - pub const MAX_CLIENT: StreamId = StreamId((u32::MAX >> 1) - 1); - /// Parse the stream ID #[inline] pub fn parse(buf: &[u8]) -> (StreamId, bool) { diff --git a/src/proto/connection.rs b/src/proto/connection.rs index c66c003..c1b5ee1 100644 --- a/src/proto/connection.rs +++ b/src/proto/connection.rs @@ -383,14 +383,14 @@ where // // > A server that is attempting to gracefully shut down a connection // > SHOULD send an initial GOAWAY frame with the last stream - // > identifier set to 231-1 and a NO_ERROR code. This signals to the + // > identifier set to 2^31-1 and a NO_ERROR code. This signals to the // > client that a shutdown is imminent and that initiating further // > requests is prohibited. After allowing time for any in-flight // > stream creation (at least one round-trip time), the server can // > send another GOAWAY frame with an updated last stream identifier. // > This ensures that a connection can be cleanly shut down without // > losing requests. - self.go_away(StreamId::MAX_CLIENT, Reason::NO_ERROR); + self.go_away(StreamId::MAX, Reason::NO_ERROR); // We take the advice of waiting 1 RTT literally, and wait // for a pong before proceeding. diff --git a/src/proto/go_away.rs b/src/proto/go_away.rs index ebcb6c6..32eb90f 100644 --- a/src/proto/go_away.rs +++ b/src/proto/go_away.rs @@ -103,7 +103,7 @@ impl GoAway { pub fn should_close_on_idle(&self) -> bool { !self.close_now && self.going_away .as_ref() - .map(|g| g.last_processed_id != StreamId::MAX_CLIENT) + .map(|g| g.last_processed_id != StreamId::MAX) .unwrap_or(false) } diff --git a/tests/server.rs b/tests/server.rs index 47e96e0..c180715 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -245,7 +245,10 @@ fn graceful_shutdown() { .request("GET", "https://example.com/") .eos(), ) - .recv_frame(frames::go_away(StreamId::MAX_CLIENT)) + // 2^31 - 1 = 2147483647 + // Note: not using a constant in the library because library devs + // can be unsmart. + .recv_frame(frames::go_away(2147483647)) .recv_frame(frames::ping(frame::Ping::SHUTDOWN)) .recv_frame(frames::headers(1).response(200).eos()) // Pretend this stream was sent while the GOAWAY was in flight