SPlit up
This commit is contained in:
parent
cf39ad754e
commit
f59d01227b
91 changed files with 10370 additions and 7562 deletions
|
|
@ -1042,7 +1042,44 @@ async fn main() -> anyhow::Result<()> {
|
|||
listener,
|
||||
app.into_make_service_with_connect_info::<std::net::SocketAddr>(),
|
||||
)
|
||||
.with_graceful_shutdown(shutdown_signal())
|
||||
.await
|
||||
.context("Server error")?;
|
||||
info!("Server shut down cleanly");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Resolves on SIGTERM or SIGINT so in-flight requests (exports, checkouts)
|
||||
/// can drain before the process exits. The realtime SSE proxy connections
|
||||
/// never complete, so a watchdog force-exits before Docker's default 10s
|
||||
/// stop grace period elapses and it sends SIGKILL.
|
||||
async fn shutdown_signal() {
|
||||
let ctrl_c = async {
|
||||
tokio::signal::ctrl_c()
|
||||
.await
|
||||
.expect("Failed to install SIGINT handler");
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
let terminate = async {
|
||||
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
|
||||
.expect("Failed to install SIGTERM handler")
|
||||
.recv()
|
||||
.await;
|
||||
};
|
||||
|
||||
#[cfg(not(unix))]
|
||||
let terminate = std::future::pending::<()>();
|
||||
|
||||
tokio::select! {
|
||||
() = ctrl_c => {},
|
||||
() = terminate => {},
|
||||
}
|
||||
info!("Shutdown signal received; draining in-flight requests");
|
||||
|
||||
tokio::spawn(async {
|
||||
tokio::time::sleep(Duration::from_secs(8)).await;
|
||||
tracing::warn!("Graceful shutdown drain timed out after 8s; forcing exit");
|
||||
std::process::exit(0);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue