diff options
author | Jordan Wu <[email protected]> | 2024-09-18 02:08:07 +0000 |
---|---|---|
committer | Kevin Guthrie <[email protected]> | 2024-10-28 11:14:19 -0400 |
commit | 04d7cfeef6205d2cf33ad5704a363ee107250771 (patch) | |
tree | 32d4a28ef93f2d243c25ffc7b1ecf23e9e46c345 | |
parent | 3f60857993925c87aecfbaf0799358baabf7d436 (diff) | |
download | pingora-04d7cfeef6205d2cf33ad5704a363ee107250771.tar.gz pingora-04d7cfeef6205d2cf33ad5704a363ee107250771.zip |
shutdown h2 connection gracefully with GOAWAYs
Co-authored-by: Matthew Gumport <[email protected]>
Includes-commit: 15e5c64ce46da5e061f2c84ce45cdddedf2f6058
Replicated-from: https://github.com/cloudflare/pingora/pull/415
-rw-r--r-- | .bleep | 2 | ||||
-rw-r--r-- | pingora-core/src/apps/mod.rs | 13 |
2 files changed, 12 insertions, 3 deletions
@@ -1 +1 @@ -78684dca2f7fe5d952d3b01faec526a1b1cbad8c
\ No newline at end of file +a4032182c556d6fee5f22d0b56b99b03c8fc6868
\ No newline at end of file diff --git a/pingora-core/src/apps/mod.rs b/pingora-core/src/apps/mod.rs index 0786d08..2a77a3d 100644 --- a/pingora-core/src/apps/mod.rs +++ b/pingora-core/src/apps/mod.rs @@ -20,6 +20,7 @@ pub mod prometheus_http_app; use crate::server::ShutdownWatch; use async_trait::async_trait; use log::{debug, error}; +use std::future::poll_fn; use std::sync::Arc; use crate::protocols::http::v2::server; @@ -148,11 +149,19 @@ where Ok(c) => c, }; + let mut shutdown = shutdown.clone(); loop { // this loop ends when the client decides to close the h2 conn // TODO: add a timeout? - let h2_stream = - server::HttpSession::from_h2_conn(&mut h2_conn, digest.clone()).await; + let h2_stream = tokio::select! { + _ = shutdown.changed() => { + h2_conn.graceful_shutdown(); + let _ = poll_fn(|cx| h2_conn.poll_closed(cx)) + .await.map_err(|e| error!("H2 error waiting for shutdown {e}")); + return None; + } + h2_stream = server::HttpSession::from_h2_conn(&mut h2_conn, digest.clone()) => h2_stream + }; let h2_stream = match h2_stream { Err(e) => { // It is common for the client to just disconnect TCP without properly |