aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
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;
}
}