{"record":{"id":"6d66d3a242625c33","repo":"tokio-rs/tokio","slug":"signal-too-large","errorCode":null,"errorMessage":"signal too large","messagePattern":"signal too large","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"tokio/src/signal/unix.rs","lineNumber":284,"sourceCode":"///\n/// This will register the signal handler if it hasn't already been registered,\n/// returning any error along the way if that fails.\nfn signal_enable(signal: SignalKind, handle: &Handle) -> io::Result<()> {\n    let signal = signal.0;\n    if signal <= 0 || signal_hook_registry::FORBIDDEN.contains(&signal) {\n        return Err(Error::new(\n            ErrorKind::Other,\n            format!(\"Refusing to register signal {signal}\"),\n        ));\n    }\n\n    // Check that we have a signal driver running\n    handle.check_inner()?;\n\n    let globals = globals();\n    let siginfo = match globals.storage().get(signal as EventId) {\n        Some(slot) => slot,\n        None => return Err(io::Error::new(io::ErrorKind::Other, \"signal too large\")),\n    };\n\n    siginfo\n        .init\n        .get_or_init(|| {\n            unsafe { signal_hook_registry::register(signal, move || action(globals, signal)) }\n                .map(|_| ())\n                .map_err(|e| e.raw_os_error())\n        })\n        .map_err(|e| {\n            e.map_or_else(\n                || Error::new(ErrorKind::Other, \"registering signal handler failed\"),\n                Error::from_raw_os_error,\n            )\n        })\n}\n\n/// An listener for receiving a particular type of OS signal.","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/tokio-rs/tokio/blob/625954f365727668cb02d04172b34f1149637728/tokio/src/signal/unix.rs#L266-L302","documentation":"signal_enable returns 'signal too large' when globals().storage().get(signal as EventId) returns None — the internal per-signal storage array has no slot for the requested number, meaning it exceeds the compiled maximum signal index tokio tracks.","triggerScenarios":"Calling unix::signal with a signal number larger than tokio's compiled signal storage capacity (NSIG-derived upper bound).","commonSituations":"Using real-time signals (SIGRTMIN+n) on platforms where the number exceeds tokio's slot count; passing a very large platform-specific signal constant; miscomputing a signal offset.","solutions":["Use standard signals (<= 31 on Linux) which always fit.","Check the signal number is below NSIG/signal_hook_registry's maximum before registering.","Upgrade tokio — newer versions may expand the supported range.","For real-time signals, confirm the specific number fits within tokio's storage."],"exampleFix":"// before\nlet s = signal(SignalKind::from_raw(60))?; // may exceed storage\n// after\nlet num = 60;\nif num >= libc::NSIG { return Err(io::Error::new(io::ErrorKind::Other, \"signal too large\")); }\nlet s = signal(SignalKind::from_raw(num))?","handlingStrategy":"validation","validationCode":"if num as usize >= libc::NSIG {\n    return Err(io::Error::new(io::ErrorKind::Other, \"signal too large\"));\n}\nsignal(SignalKind::from_raw(num))?","typeGuard":"fn within_signal_storage(sig: i32) -> bool {\n    sig > 0 && (sig as usize) < libc::NSIG\n}","tryCatchPattern":"match signal(SignalKind::from_raw(num)) {\n    Ok(s) => s,\n    Err(e) if e.to_string().contains(\"signal too large\") => return Err(e),\n    Err(e) => return Err(e),\n}","preventionTips":["Stick to standard signals (<= 31 on Linux).","Validate against NSIG before using real-time signals.","Upgrade tokio for wider signal storage support."],"tags":["signal","signal-handling","unix","validation","io-error"],"backgroundTag":null,"analyzedSha":"625954f365727668cb02d04172b34f1149637728","analyzedAt":"2026-08-11T17:46:45.378Z","contentChangedAt":"2026-08-11T17:46:45.378Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}