aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJordan Wu <[email protected]>2024-09-18 02:08:07 +0000
committerKevin Guthrie <[email protected]>2024-10-26 22:50:00 -0400
commit5b9ded27b7f7e638bebb5917284837fdf98a4186 (patch)
tree32d4a28ef93f2d243c25ffc7b1ecf23e9e46c345
parent3f60857993925c87aecfbaf0799358baabf7d436 (diff)
downloadpingora-bleeper-kevinbartlett-72b8880751.tar.gz
pingora-bleeper-kevinbartlett-72b8880751.zip
shutdown h2 connection gracefully with GOAWAYsbleeper-kevinbartlett-72b8880751
Co-authored-by: Matthew Gumport <[email protected]> Includes-commit: 15e5c64ce46da5e061f2c84ce45cdddedf2f6058 Replicated-from: https://github.com/cloudflare/pingora/pull/415
-rw-r--r--.bleep2
-rw-r--r--pingora-core/src/apps/mod.rs13
2 files changed, 12 insertions, 3 deletions
diff --git a/.bleep b/.bleep
index 26298b0..0c316c3 100644
--- a/.bleep
+++ b/.bleep
@@ -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