{"record":{"id":"3b92ff381ead8b4e","repo":"imsnif/bandwhich","slug":"failed-to-set-sigint-handler","errorCode":null,"errorMessage":"failed to set SIGINT handler","messagePattern":"failed to set SIGINT handler","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":112,"sourceCode":"pub fn start<B>(terminal_backend: B, os_input: OsInputOutput, opts: Opt)\nwhere\n    B: Backend + Send + 'static,\n{\n    let running = Arc::new(AtomicBool::new(true));\n    let paused = Arc::new(AtomicBool::new(false));\n    let last_start_time = Arc::new(RwLock::new(Instant::now()));\n    let cumulative_time = Arc::new(RwLock::new(Duration::new(0, 0)));\n    let table_cycle_offset = Arc::new(AtomicUsize::new(0));\n\n    // handle SIGINT properly instead of as a keypress\n    // see https://github.com/imsnif/bandwhich/issues/487\n    #[cfg(not(test))]\n    {\n        let running = running.clone();\n        ctrlc::set_handler(move || {\n            running.store(false, Ordering::Release);\n        })\n        .expect(\"failed to set SIGINT handler\");\n    }\n\n    let mut active_threads = vec![];\n\n    let terminal_events = os_input.terminal_events;\n    let get_open_sockets = os_input.get_open_sockets;\n    let mut write_to_stdout = os_input.write_to_stdout;\n    let mut dns_client = os_input.dns_client;\n\n    let raw_mode = opts.raw;\n\n    let network_utilization = Arc::new(Mutex::new(Utilization::new()));\n    let ui = Arc::new(Mutex::new(Ui::new(terminal_backend, &opts)));\n\n    let display_handler = thread::Builder::new()\n        .name(\"display_handler\".to_string())\n        .spawn({\n            let running = running.clone();","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/imsnif/bandwhich/blob/1899870cea8bb377948f05cfea64733ec6ea2cd6/src/main.rs#L94-L130","documentation":"At this point in start(), bandwhich registers a SIGINT handler (via the signal_hook crate) so that Ctrl+C terminates the process cleanly instead of being consumed as a regular keypress by the terminal event loop (per issue #487). This error fires when the underlying OS-level signal registration call fails — e.g. signal_hook's register/flag returns an Err, which happens on OS errors such as reaching the per-process limit of registered signal handlers, or unsupported/broken signal APIs on the platform. Since clean shutdown on Ctrl+C is mandatory, start() aborts startup with this message rather than running a session that cannot be interrupted gracefully.","triggerScenarios":"`ctrlc::set_handler` returning Err — typically when creating the signal pipe/handler fails, e.g. resource exhaustion (too many file descriptors, no signal dispositions available) or unsupported/locked-down environments.","commonSituations":"Containers or sandboxed environments with restricted signal handling or fd limits (ulimit -n exhausted), heavily constrained CI runners, or unusual platforms where the ctrlc crate's mechanism (eventfd/signal) is unavailable.","solutions":["Check and raise the file descriptor limit (`ulimit -n`) if fds are exhausted","Retry in a normal environment — this is usually environmental, not a code bug","If signal handling cannot work in your sandbox, run bandwhich directly in a standard shell/terminal","Upgrade bandwhich/ctrlc if on an old version with known platform issues"],"exampleFix":"// before\nbandwhich  # in sandbox with fd exhaustion: panicked at 'failed to set SIGINT handler'\n// after\nulimit -n 4096 && bandwhich","handlingStrategy":"try-catch","validationCode":"// shell: preflight fd availability\ncurrent=$(ulimit -n)\nif [ \"$current\" -lt 256 ]; then ulimit -n 4096; fi","typeGuard":null,"tryCatchPattern":"if let Err(e) = ctrlc::set_handler(move || { running.store(false, Ordering::Release); }) {\n    eprintln!(\"SIGINT handler unavailable: {e}; Ctrl+C will kill abruptly\");\n}","preventionTips":["Avoid running in environments that restrict signal handling or exhaust file descriptors","Raise `ulimit -n` before starting long-running captures","Test the deployment sandbox before running bandwhich there","Keep ctrlc/bandwhich versions current for platform fixes"],"tags":["rust","signals","sigint","ctrlc"],"backgroundTag":"unsupported-platform","analyzedSha":"1899870cea8bb377948f05cfea64733ec6ea2cd6","analyzedAt":"2026-09-08T10:26:38.858Z","contentChangedAt":"2026-09-08T10:26:38.858Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}