diff options
| author | tv <tv@krebsco.de> | 2026-10-30 18:12:31 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-30 18:12:31 +0100 |
| commit | 0ef6785b09d74878f66449f18cf45fe54f8b2f5a (patch) | |
| tree | 36340b8b96ea780e266611159711a4d357cab4bf /src/main.rs | |
| parent | 46a7d204c81b002f960a9bca97941df7a98c43d4 (diff) | |
dasboard cannot block shutdown
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index da79668..533f85b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -243,7 +243,14 @@ async fn main() -> Result<()> { // The API is up while the node joins: what it serves then is the handlers' business // (`docs/lifecycle.md`), and /peers and /admin/stats show how joining goes. let joined = AtomicBool::new(false); - let app = api::router(state.clone(), auth_state, args.debug_api); + // True once the node stops: the server drains, and long-lived responses end. + let (closing_tx, closing_rx) = watch::channel(false); + let app = api::router( + state.clone(), + auth_state, + args.debug_api, + closing_rx.clone(), + ); let listener = tokio::net::TcpListener::bind(args.bind_addr) .await @@ -251,10 +258,8 @@ async fn main() -> Result<()> { info!(address = %listener.local_addr()?, "HTTP API listening"); - let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel::<()>(); - let server_builder = axum::serve(listener, app).with_graceful_shutdown(async move { - let _ = shutdown_rx.await; + stopped(closing_rx).await; info!("Shutdown signal received. Draining API connections...") }); @@ -281,14 +286,14 @@ async fn main() -> Result<()> { tokio::select! { failed = joining.as_mut() => { - let _ = shutdown_tx.send(()); + closing_tx.send_replace(true); let _ = server_fut.as_mut().await; return failed; } exit_status = state.transport.wait_for_exit() => { error!(status = ?exit_status, "A transport stopped"); - let _ = shutdown_tx.send(()); + closing_tx.send_replace(true); let _ = server_fut.as_mut().await; } @@ -301,7 +306,7 @@ async fn main() -> Result<()> { } _ = stopped(stop.clone()) => { - let _ = shutdown_tx.send(()); + closing_tx.send_replace(true); let _ = server_fut.as_mut().await; } } |
