Skip to main content

Module shutdown

Module shutdown 

Source
Expand description

Graceful-shutdown signal handling — SIGINT and SIGTERM in one place, so no serve path handles only half of them. See shutdown::shutdown_signal. Graceful-shutdown signal handling. Every serve path uses this one function, so they cannot disagree.

§Why ctrl_c() alone is not enough

On Unix tokio::signal::ctrl_c() waits for SIGINT only. But Kubernetes, docker stop and systemd all send SIGTERM, which kills the process by default. A server waiting on ctrl_c() therefore drains on a laptop and dies mid-request in production, with exit code 0 and nothing in the log.

Constants§

DEFAULT_DRAIN_TIMEOUT
How long open connections get after the stop signal, when server.shutdown_timeout_secs is unset (#1883).

Functions§

serve_until_drained
Serve app until shutdown_signal, then give open connections drain to finish. SSE and long-poll never finish on their own, so without a deadline SIGTERM waited for SIGKILL (#1883). This is the crate’s only axum::serve, so no serve path can skip the drain (#1948).
shutdown_signal
Waits until the process is asked to stop, by Ctrl-C (SIGINT) or SIGTERM. Off Unix, only Ctrl-C.

Type Aliases§

StopSignal
The signal a graceful server stops accepting on.