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_secsis unset (#1883).
Functions§
- serve_
until_ drained - Serve
appuntilshutdown_signal, then give open connectionsdrainto finish. SSE and long-poll never finish on their own, so without a deadline SIGTERM waited for SIGKILL (#1883). This is the crate’s onlyaxum::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§
- Stop
Signal - The signal a graceful server stops accepting on.