Skip to content

Commit

Permalink
shutdown h2 connection gracefully with GOAWAYs
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-wu-97 committed Sep 19, 2024
1 parent 6c8e7aa commit 03a5b99
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pingora-core/src/apps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,20 @@ 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();
// continue to the next loop to wait for client disconnect before returning.
// the client will disconnect when all in flight streams are closed.
continue;
}
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
Expand Down

0 comments on commit 03a5b99

Please sign in to comment.