From b7a0c2d5967d9ca22bd5e031166876c81ae80606 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 6 Jun 2018 13:00:59 -0700 Subject: [PATCH] fix(http2): implement `graceful_shutdown` for HTTP2 server connections Closes #1550 --- src/proto/h2/server.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index bc3ba74de2..fa6e7feb82 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -26,6 +26,7 @@ where { Handshaking(Handshake>), Serving(Serving), + Closed, } struct Serving @@ -55,7 +56,20 @@ where } pub fn graceful_shutdown(&mut self) { - unimplemented!("h2 server graceful shutdown"); + trace!("graceful_shutdown"); + match self.state { + State::Handshaking(..) => { + // fall-through, to replace state with Closed + }, + State::Serving(ref mut srv) => { + srv.conn.graceful_shutdown(); + return; + }, + State::Closed => { + return; + } + } + self.state = State::Closed; } } @@ -82,6 +96,11 @@ where State::Serving(ref mut srv) => { return srv.poll_server(&mut self.service, &self.exec); } + State::Closed => { + // graceful_shutdown was called before handshaking finished, + // nothing to do here... + return Ok(Async::Ready(())); + } }; self.state = next; }