Skip to main content

shutdown_signal

Function shutdown_signal 

Source
pub fn shutdown_signal() -> Result<impl Future<Output = ()> + Send + 'static>
Expand description

Waits for Ctrl+C (SIGINT), or on Unix, SIGTERM – so a service manager’s ordinary “stop” request (systemctl stop, launchctl stop) drains in-flight requests the same way an interactive Ctrl+C does, rather than dropping connections mid-response. Unix signal handlers are installed when this function is called, before the server starts accepting connections, so an immediate shutdown signal cannot hit the default process handler. The Windows Service Control Manager’s own Stop/Shutdown control codes don’t arrive as either of these signals – see crate::service::windows_impl::run_service for the SCM-specific equivalent used instead when running as a Windows service. Installing a handler returns an error instead of panicking, so a failed install cannot take down a process that may already be serving requests.