From 3ff5bc52983e665eb91f18ca1e7694c5591b075f Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 9 Feb 2024 20:11:54 -0500 Subject: [PATCH] ask systemd for more time when shutting down if needed, raise axum shutdown timeout to 3 mins Signed-off-by: strawberry --- src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 05db3af8..314e978c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -565,14 +565,28 @@ async fn shutdown_signal(handle: ServerHandle, tx: Sender<()>) -> Result<()> { } warn!("Received {}, shutting down...", sig); - handle.graceful_shutdown(Some(Duration::from_secs(60))); + let shutdown_time_elapsed = tokio::time::Instant::now(); + handle.graceful_shutdown(Some(Duration::from_secs(180))); services().globals.shutdown(); #[cfg(feature = "systemd")] let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Stopping]); + tx.send(()).unwrap(); + if shutdown_time_elapsed.elapsed() >= Duration::from_secs(60) && cfg!(feature = "systemd") { + warn!("Still shutting down after 60 seconds since receiving shutdown signal, asking systemd for more time (+120 seconds). Remaining connections: {}", handle.connection_count()); + + #[cfg(feature = "systemd")] + let _ = sd_notify::notify(true, &[sd_notify::NotifyState::ExtendTimeoutUsec(120)]); + } + + warn!( + "Time took to shutdown: {:?} seconds", + shutdown_time_elapsed.elapsed() + ); + Ok(()) }