Skip to content

Commit

Permalink
fix an issue that prevented the process to receive SIGTERM
Browse files Browse the repository at this point in the history
  • Loading branch information
whisperpine committed Nov 17, 2023
1 parent 90214c5 commit 7f7ef23
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,31 @@ use uuid::Uuid;
///
/// Shutdown the server when pressing Ctrl+C.
pub async fn shutdown() {
tokio::signal::ctrl_c().await.unwrap();
info!("shutdown");
use tokio::signal;

let ctrl_c = async {
signal::ctrl_c()
.await
.expect("failed to install Ctrl+C handler");
};

#[cfg(unix)]
let terminate = async {
signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("failed to install signal handler")
.recv()
.await;
};

#[cfg(not(unix))]
let terminate = std::future::pending::<()>();

tokio::select! {
_ = ctrl_c => {},
_ = terminate => {},
}

tracing::info!("starting graceful shutdown");
}

/// Routing fallback
Expand Down

0 comments on commit 7f7ef23

Please sign in to comment.