{"record":{"id":"d84308eb9a3affe5","repo":"loco-rs/loco","slug":"failed-to-install-ctrl-c-handler","errorCode":null,"errorMessage":"failed to install Ctrl+C handler","messagePattern":"failed to install Ctrl\\+C handler","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/boot.rs","lineNumber":582,"sourceCode":"    Ok(())\n}\n\n#[must_use]\npub fn list_endpoints<H: Hooks>(ctx: &AppContext) -> Vec<ListRoutes> {\n    H::routes(ctx).collect()\n}\n\n/// Waits for a shutdown signal, either via Ctrl+C or termination signal.\n///\n/// # Panics\n///\n/// This function will panic if it fails to install the signal handlers for\n/// Ctrl+C or the terminate signal on Unix-based systems.\npub async fn shutdown_signal() {\n    let ctrl_c = async {\n        signal::ctrl_c()\n            .await\n            .expect(\"failed to install Ctrl+C handler\");\n    };\n\n    #[cfg(unix)]\n    let terminate = async {\n        signal::unix::signal(signal::unix::SignalKind::terminate())\n            .expect(\"failed to install signal handler\")\n            .recv()\n            .await;\n    };\n\n    #[cfg(not(unix))]\n    let terminate = std::future::pending::<()>();\n\n    tokio::select! {\n        () = ctrl_c => {},\n        () = terminate => {},\n    }\n}","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/loco-rs/loco/blob/23639d1e360dbc618073642b507d6f8664adbaff/src/boot.rs#L564-L600","documentation":"Panic in `shutdown_signal` when the tokio Ctrl+C (or Unix SIGTERM) signal handler cannot be installed. The function promises graceful shutdown, so rather than continuing without signal handling it panics, per its documented behavior.","triggerScenarios":"Starting the server via `cargo loco start` / `serve` in an environment where the signal handler registration fails — typically OS-level restrictions, resource exhaustion, or runtimes lacking signal support.","commonSituations":"Running inside restricted containers/sandboxes (some minimal containers, seccomp profiles, WSL edge cases); hitting RLIMIT on signal descriptors; unusual process supervisors blocking signal APIs.","solutions":["Run the server in an environment that permits installing signal handlers (check container security profiles/seccomp)","Check process resource limits (`ulimit -i`) and the OS for signal-related restrictions","Bypass by sending signals differently or patching `shutdown_signal` to log-and-continue if your deployment never needs graceful shutdown","Update tokio if the failure comes from a known tokio signal-handling bug"],"exampleFix":"// before\nsignal::ctrl_c().await.expect(\"failed to install Ctrl+C handler\");\n// after\nif signal::ctrl_c().await.is_err() {\n    tracing::warn!(\"Ctrl+C handler unavailable; graceful shutdown disabled\");\n    std::future::pending::<()>().await;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"tokio::select! {\n    _ = shutdown_signal() => { /* graceful shutdown */ }\n    _ = std::future::pending::<()>() => {}\n} // wrap the runner in a supervisor that restarts and alerts if the process panics here","preventionTips":["Test server startup in the target container/sandbox environment","Keep container seccomp profiles permissive for signal syscalls","Monitor for panics at boot and alert before they hit production"],"tags":["signals","shutdown","panic","unix","tokio"],"backgroundTag":"module-init-failed","analyzedSha":"23639d1e360dbc618073642b507d6f8664adbaff","analyzedAt":"2026-09-12T01:47:20.769Z","contentChangedAt":"2026-09-12T01:47:20.769Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}