From 0bb3924836205a0364aaf0959c7cf387db004794 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 03:54:19 +0100 Subject: unify closing logic --- src/main.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 533f85b..617ca94 100644 --- a/src/main.rs +++ b/src/main.rs @@ -243,14 +243,7 @@ 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); - // 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 app = api::router(state.clone(), auth_state, args.debug_api); let listener = tokio::net::TcpListener::bind(args.bind_addr) .await @@ -258,8 +251,10 @@ async fn main() -> Result<()> { info!(address = %listener.local_addr()?, "HTTP API listening"); + // The node shutting down (`AppState::closing`): the server drains. + let closing = state.closing.subscribe(); let server_builder = axum::serve(listener, app).with_graceful_shutdown(async move { - stopped(closing_rx).await; + stopped(closing).await; info!("Shutdown signal received. Draining API connections...") }); @@ -286,14 +281,14 @@ async fn main() -> Result<()> { tokio::select! { failed = joining.as_mut() => { - closing_tx.send_replace(true); + state.closing.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"); - closing_tx.send_replace(true); + state.closing.send_replace(true); let _ = server_fut.as_mut().await; } @@ -306,7 +301,7 @@ async fn main() -> Result<()> { } _ = stopped(stop.clone()) => { - closing_tx.send_replace(true); + state.closing.send_replace(true); let _ = server_fut.as_mut().await; } } -- cgit v1.3.1