From 6484545b09291b281baafef11b743b224d196515 Mon Sep 17 00:00:00 2001 From: Artem Medvedev Date: Wed, 27 Mar 2024 10:23:24 +0100 Subject: [PATCH] fix: graceful shutdown after switch to hyper `1.x` (#779) For some reason it was removed after switch to `hyper 1.x` ([commit](https://github.com/poem-web/poem/commit/0b6ca89be9636472b25f3677dc957fe098f72fab))
Patch affected the behavior ```patch - let mut conn = Http::new() - .serve_connection(socket, service) - .with_upgrades(); + let builder = auto::Builder::new(hyper_util::rt::TokioExecutor::new()); + let conn = + builder.serve_connection_with_upgrades(hyper_util::rt::TokioIo::new(socket), service); + futures_util::pin_mut!(conn); tokio::select! { - _ = &mut conn => { + _ = conn => { // Connection completed successfully. return; }, @@ -366,10 +368,4 @@ } _ = server_graceful_shutdown_token.cancelled() => {} } - - // Init graceful shutdown for connection (`GOAWAY` for `HTTP/2` or disabling `keep-alive` for `HTTP/1`) - Pin::new(&mut conn).graceful_shutdown(); - - // Continue awaiting after graceful-shutdown is initiated to handle existed requests. - let _ = conn.await; ```
--- poem/src/server.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/poem/src/server.rs b/poem/src/server.rs index 6da5be1e8a..1460481bfc 100644 --- a/poem/src/server.rs +++ b/poem/src/server.rs @@ -360,7 +360,7 @@ async fn serve_connection( futures_util::pin_mut!(conn); tokio::select! { - _ = conn => { + _ = &mut conn => { // Connection completed successfully. }, _ = connection_shutdown_token.cancelled() => { @@ -368,4 +368,9 @@ async fn serve_connection( } _ = server_graceful_shutdown_token.cancelled() => {} } + + // Init graceful shutdown for connection + conn.as_mut().graceful_shutdown(); + // Continue awaiting after graceful-shutdown is initiated to handle existed requests. + let _ = conn.await; }