{"record":{"id":"326906f7e372928d","repo":"tracel-ai/burn","slug":"failed-to-install-ctrl-c-handler-326906","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":"crates/burn-remote/src/server/spawn.rs","lineNumber":30,"sourceCode":"pub(crate) fn spawn_detached<F>(future: F)\nwhere\n    F: Future<Output = ()> + 'static,\n{\n    wasm_bindgen_futures::spawn_local(future);\n}\n\n/// Resolve when the process is asked to stop (Ctrl+C, or `SIGTERM` on Unix).\n///\n/// The single shutdown trigger shared by the turnkey WebSocket and Iroh server entry points.\n#[cfg(all(\n    not(target_family = \"wasm\"),\n    any(feature = \"websocket\", feature = \"iroh\")\n))]\npub(crate) async fn os_shutdown_signal() {\n    let ctrl_c = async {\n        tokio::signal::ctrl_c()\n            .await\n            .expect(\"failed to install Ctrl+C handler\");\n    };\n\n    #[cfg(unix)]\n    let terminate = async {\n        tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())\n            .expect(\"failed to install signal handler\")\n            .recv()\n            .await;\n    };\n    #[cfg(not(unix))]\n    let terminate = std::future::pending::<()>();\n\n    tokio::select! {\n        _ = ctrl_c => {},\n        _ = terminate => {},\n    }\n}\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-remote/src/server/spawn.rs#L12-L48","documentation":"os_shutdown_signal installs a tokio Ctrl+C handler; the expect panics if the handler cannot be installed. tokio::signal::ctrl_c() fails when the OS event registration errors (e.g. signal dispositions unavailable in the environment).","triggerScenarios":"Calling the server spawn path (websocket/iroh features) in an environment where SIGINT handling cannot be registered — embedded runtimes, containers without signal support, sandboxed environments.","commonSituations":"Running inside sandboxed CI or WASM-adjacent hosts lacking SIGINT; process already has conflicting signal handlers; resource exhaustion in the signal subsystem.","solutions":["Run the server in a normal OS process environment that supports SIGINT (not a restricted sandbox)","Provide a custom shutdown signal source instead of relying on ctrl_c","Check for code that previously set SIGINT to SIG_IGN or intercepted it incompatibly","Upgrade tokio if a signal-registration bug is suspected"],"exampleFix":"// before\nserver.start_async().await; // uses ctrl_c internally\n// after\nlet shutdown = async { tokio::time::sleep(Duration::from_secs(3600)).await; }; // custom signal\nserver.start_async_with(shutdown).await; // if such an API exists, else run in supporting env","handlingStrategy":"fallback","validationCode":"// Check the environment supports SIGINT before spawning the server\nif !signal_supports_interrupt() { /* use custom shutdown future */ }","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| server_thread.join())\n    .map_err(|_| anyhow!(\"server aborted: could not install Ctrl+C handler\"))?;","preventionTips":["Run the server in a full OS process environment, not a restricted sandbox","Avoid global SIGINT manipulation before starting the server","Supply a custom shutdown signal future where signal APIs are unavailable"],"tags":["rust","tokio","signals","shutdown"],"backgroundTag":"signal-handler-install-failed","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}