Preserve the app-server shutdown signal future across loop iterations (#45849)

## What changed

Keep `shutdown_signal()` pinned across `tokio::select!` iterations and reset it only when it completes, so other events do not cancel and recreate the pending signal listener.

## Testing

Update the WebSocket drain interruption test to use gated responses and keep a second turn active until the `turn/interrupt` reply arrives, preventing shutdown from racing the reply.

GitOrigin-RevId: c939d84ed0e09c2ee49229e81a3becdfa6a4c7f1
This commit is contained in:
jgershen-oai authored and copyberry committed 2026-09-16 03:30:44 +00:00
1 parent ffae979216
commit 90f7b37d23
2 files changed
+42 -9

No files matched your search

+3 -1
View File
@@ -1022,6 +1022,7 @@ pub async fn run_main_with_transport_options(
let mut snapshot_finished = !managed_daemon;
let mut clients_disconnected = false;
let mut shutdown_state = ShutdownState::default();
let mut shutdown_signal_future = Box::pin(shutdown_signal());
let exit_reason = loop {
// Sample submissions first: one can publish a running turn before
// releasing its permit, and shutdown must observe that new turn.
@@ -1057,7 +1058,8 @@ pub async fn run_main_with_transport_options(
_ = &mut snapshot, if shutdown_state.requested() && active_admissions == 0 && !snapshot_finished => {
snapshot_finished = true;
}
shutdown_signal_result = shutdown_signal(), if graceful_signal_restart_enabled && !shutdown_state.forced() => {
shutdown_signal_result = &mut shutdown_signal_future, if graceful_signal_restart_enabled && !shutdown_state.forced() => {
shutdown_signal_future.set(shutdown_signal());
let signal = match shutdown_signal_result {
Ok(signal) => signal,
Err(err) => {