Repository navigation
Conversation
process.kill(pid, name) and the process.on(name) signal-handler wiring
both look up the signal number through signalNameToNumberMap in
BunProcess.cpp. That table was missing SIGSTKFLT, SIGPOLL and SIGPWR on
Linux, while os.constants.signals and the subprocess.kill path already
carried them. The result was that process.kill threw ERR_UNKNOWN_SIGNAL
for a name subprocess.kill accepted, and process.on for those names
registered a listener without installing a sigaction, so the first
delivery killed the process with a JS handler attached.
Add the three names to both the name->number and number->name tables
under the same #ifdef guards the other Linux-only signals use.
Bun__onSignalForJS previously looked up a single name for a signal
number, so listeners registered under an alias name (SIGIOT for SIGABRT,
SIGPOLL for SIGIO) never fired. It now emits the event for every name
that resolves to the delivered number, matching Node.js. The existing
Linux guard that skips g_wtfConfig.sigThreadSuspendResume keeps
process.on('SIGPWR') from replacing JSC's thread-suspend handler.
|
Updated 3:41 PM PT - Jul 8th, 2026
❌ @robobun, your commit bc42433 has 2 failures in
🧪 To try this PR locally: bunx bun-pr 33776That installs a local version of the PR into your bun-33776 --bun |
|
Found 1 issue this PR may fix:
🤖 Generated with Claude Code |
|
Warning Review limit reached
Next review available in: 4 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis PR adds support for SIGSTKFLT, SIGPOLL, and SIGPWR signal aliases in BunProcess.cpp by extending name/number maps and increasing map capacity. Bun__onSignalForJS now dispatches events for every alias sharing a signal number. New Linux-only tests validate process.kill and process.on signal behavior. ChangesSignal Alias Handling
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
|
Checked #12918: the |
The uninstall path in onDidChangeListeners keyed the OS handler on the signal number but only checked the listener count of the event name being removed. With aliased signals (SIGABRT/SIGIOT, SIGIO/SIGPOLL) removing the last listener for one name restored SIG_DFL while the other name still had a listener, so the next delivery killed the process. Sum listener counts over every name that resolves to the same signal number before restoring the default disposition.
ProcessBindingConstants.cpp adds SIGUNUSED and SIGLOST to os.constants.signals under #ifdef (musl defines SIGUNUSED as SIGSYS), so the maps need matching entries or process.kill throws ERR_UNKNOWN_SIGNAL for a name os.constants.signals advertises. Both alias existing numbers, so the alias-aware emit and uninstall paths already handle them.
|
The diff is ready. Both CI runs (builds 70605 and 70623) passed the four new tests in |
|
Closing as part of a cleanup of stale pull requests. This PR has had no new commits since 2026-07-08, it conflicts with main, and its last CI run failed. This is not a judgment on the fix itself. If the problem still reproduces on a current build, reopen this PR after a rebase or open a new one against main. |
…umbers (#39970) Fixes #35296 ### Problem - On macOS, `subprocess.signalCode` names the platform's number with the Linux table: a child killed by SIGBUS (10 there) reports `"SIGUSR1"` (build 102638). `kill("SIGUSR1")` sends 10, which is SIGBUS there. - A signal with no name (a Linux real-time signal) is handled four ways: `exited` is 128 + n or 254, `bun run` exits 1, `Bun.$` never completes, and `signalCode` is null. - Cause: `bun_core::SignalCode` (`src/bun_core/Global.rs:239`) has Linux numbers on every platform. `Status::signal_code()` (`src/spawn/process.rs:768`) looked the raw `WTERMSIG` number up in it, and `kill()` sent the table's number. ### Fix - `bun_core::SignalCode` holds only the signals the target has, and a discriminant is the target's own number: `libc::SIG*` on unix, the CRT and libuv numbers on Windows. `platform_number()` (#34660) and each `None` fallback are gone. Signal 16 on Linux is `SIGSTKFLT`, node's name. - `Status::signal()` is the raw platform number. Exit codes, re-raises and `signalCode` use it. `Status::signal_code()` is the named signal, used only to name or classify. - Correct because a variant cannot exist without a number, so each conversion to the OS is a cast. A number without a name is reported as the number. A name the platform lacks is an unknown name. - Verified: new cases in seven test files (see the notes), with cases that fail on stock bun on Linux. Also `cargo check` for five targets and a Windows debug build. ### Background - Signal numbers are per OS. Linux and the BSDs agree on about half of them. SIGSTKFLT and real-time signals are Linux-only. Windows has six CRT signals, and libuv adds four. - `bun_core::SignalCode` is a closed enum generated from one table. Its variant names are what JS sees. - `bun_sys::SignalCode(u8)` is the open newtype for any platform number, which may have no name. <details><summary>Notes</summary> - New test cases: spawn-kill-signal, child_process, shell-hang, run-propagate-sigkill, filter-workspace, bun-install-lifecycle-scripts, parallel. - Superseded and closed: #33775 (the SIGSTKFLT name), #32305 and #32321 (a signal with no name). - Shape history: the first version kept the Linux-numbered table and converted at the OS boundary with `platform_number()` and a new inverse. Review asked for no abort or panic fallbacks, so the table itself is per platform now. `raise_ignoring_panic_handler()` is unchanged from main (`sig as c_int` is correct once a discriminant is the platform's number), `bun_sys::SignalCode::of()` is a cast, the kill-signal parser has no `ERR_UNKNOWN_SIGNAL` branch, and `--watch-kill-signal` has no `platform_number().is_some()` filter and no `unwrap_or(SIGTERM)`. The one `Option` left is `from_number()`, because a real-time signal has no name. - The table: the unix rows take their numbers from `libc`, so there is no per-OS numbering to keep in sync, and the compiler rejects two variants with one number. SIGSTKFLT and SIGPWR are `cfg(any(linux, android))`. The Windows rows are the ten numbers `platform_number()` had (CRT plus libuv's `uv/win.h`). A row also carries the description for the "terminated by" messages, so the `description()` match in `bun_sys` is gone and no consumer needs a `cfg`. - A name the platform lacks: on macOS `kill("SIGPWR")` used to send signal 30, which is SIGUSR1 there. On Windows `kill("SIGUSR1")` used to throw the `ENOSYS` system error from `uv_kill`. Both now throw the existing `ERR_INVALID_ARG_TYPE` error, the same as `"SIGGOD"`, and its list holds only the platform's names. On Windows the list is `'SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGABRT', 'SIGFPE', 'SIGKILL', 'SIGSEGV', 'SIGTERM' or 'SIGWINCH'`. `--watch-kill-signal` keeps its `ERR_UNKNOWN_SIGNAL` message. node:child_process validates names in JS against `os.constants.signals`, as before. The test for this runs on macOS and Windows with SIGSTKFLT and SIGPWR. On Linux every name exists. - Windows call sites: `on_exit_uv` used `term_signal < SIGSYS` as its range check. SIGSYS is not a Windows signal, so the check is `u8::try_from(term_signal)` with 0 excluded. libuv sets `term_signal` only to a signal `uv_process_kill` accepted (SIGINT, SIGQUIT, SIGKILL, SIGTERM). `is_panic_status` reads signals only on unix. On Windows a signal status comes only from `uv_process_kill`, and none of those four is a crash signal, so the result is the same. - Surfaces that read the name: `subprocess.signalCode`, `onExit`, `Bun.spawnSync().signalCode`, node:child_process `exit`/`close`/`signalCode` and `spawnSync().signal`, the `bun test --parallel` "worker crashed" label, the `bun run --filter` label, and the `bun run` and lifecycle-script "terminated by" messages. `bun test --parallel` also classifies SIGBUS and SIGSYS deaths as crashes through the table. On macOS those two were read as SIGUSR1 and SIGUSR2 and did not abort the run, and a SIGUSR2 death was read as SIGSYS and did. - Surfaces that use the number: the `exited` promise (the one created before the exit and the one created after, which used to give 254), the shell's `$?` (the shell used to wait forever for a command killed by a real-time signal, reproduced on stock bun), the `bun run --filter` and `bun create` exit codes (used to be 1), the `bun run`, `bunx` and lifecycle re-raises (the lifecycle one used to re-raise SIGTERM), and the number the webview hooks pass to C++. - `Bun.spawn`'s `signalCode` for a signal with no name is the number. `bun.d.ts` documented that, and the code did it before the Rust port. `bun.d.ts` and `docs/runtime/child-process.mdx` now say so in the types too (`onExit`'s parameter was typed `number | null` although it received the name). - node:child_process keeps names only and reports such a death as Node does. Under Node v26.3.0 on Linux, `spawn("sh", ["-c", "kill -40 $$"])` gives `exit` and `close` `(0, null)`, `exitCode: 0`, `signalCode: null`, and `spawnSync` gives `{ status: null, signal: "" }`: `signo_string()` is `""` for a signal Node has no name for ([process_wrap.cc#L410](https://github.com/nodejs/node/blob/v26.3.0/src/process_wrap.cc#L410), [spawn_sync.cc#L732](https://github.com/nodejs/node/blob/v26.3.0/src/spawn_sync.cc#L732)), so `onexit` stores libuv's exit status, 0 ([child_process.js#L270](https://github.com/nodejs/node/blob/v26.3.0/lib/internal/child_process.js#L270)). Bun reported `(null, null)` and `signal: null`, a state Node never produces, and cluster's `isDead()` stayed false after the exit. - Fail-before on Linux comes from the Linux-visible half of each class: signal 16 was named `SIG16`, `kill("SIGSTKFLT")` threw, the CLI printed `code 16` for it, and signal 40 (a real-time signal on glibc and musl) hit every no-name path. The macOS half is covered by the same tests through SIGUSR1/SIGUSR2, which pass on Linux either way. - #35304 fixes the naming with a second X-macro table of BSD numbers. After #34660 landed `platform_number()`, that table does not build on macOS (`platform_number()` names `SIGPWR`, and the BSD table adds `SIGEMT`/`SIGINFO` variants it does not match). - `from_number()` is a linear search over the variants, once per process exit. `raise_ignoring_panic_handler_raw()` is untouched, so this does not overlap with #38877. - Removed as dead: `platform_number()`, `SIGNAL_NAMES`, `bun_core::SignalCode::from_raw()`, `bun_sys::signal_code::from_name()`, the generated `bun_sys::SignalCode::SIG*` constants (only `SIGINT`, `SIGKILL` and `DEFAULT` have users), the `description()` match in `bun_sys`, `Process::signal_code()` and the `SignalCodeExt` shim. - The tests use SIGUSR1, SIGUSR2 and, on Linux, SIGSTKFLT, because their numbers differ between Linux and the BSDs and their default action terminates without a core dump, and signals 40 and 64 for the no-name paths. The async spawn tests assert `exited === 128 + os.constants.signals[name]` as well as the name. On macOS the old code sent the wrong signal and then named it with the same wrong table, so the name alone passed. The parallel test kills with an `os.constants` number because `process.kill(pid, "SIGSTKFLT")` is a separate gap (#33776), and ASAN builds intercept a self-sent SIGBUS. - The branch is one commit on top of main plus review follow-ups. Two call sites that were new on main were adapted during the rebase: `Coordinator::abort_all` (#41467) drops `.unwrap_or(130)` because `to_exit_code()` is total, and `git_runner.rs` (#40734) uses `bun_sys::SignalCode::SIGKILL`. The shell's `Status::Err` arm (a wait error leaves `Bun.$` pending) is the same on main and is handed off as separate work. - Suites run with the Linux debug build: spawn, spawnSync, spawn-signal, spawn-maxbuf, spawn-kill-signal, bunshell, exec, shelloutput, shell-hang, filter-workspace, run-propagate-sigkill, run-crash-handler, run_command, child_process, child_process-node, parallel.test.ts, the signal cases of bun-install-lifecycle-scripts.test.ts, the three `test-watch-mode-kill-signal-*.mjs` node tests, and test/integration/bun-types. `cargo check` ran for `bun_core`, `bun_sys`, `bun_spawn`, `bun_jsc`, `bun_runtime` and `bun_install` on linux, aarch64 darwin, x86_64 windows-msvc, android and freebsd. `cargo clippy` is clean for those crates on the host. - With a Windows debug build: spawn-kill-signal.test.ts, run-crash-handler.test.ts, the signal cases of child_process.test.ts, the NTSTATUS case of parallel.test.ts, `kill("SIGKILL")` (exited 137, `signalCode` `"SIGKILL"`), and `--watch --watch-kill-signal SIGUSR1` (`ERR_UNKNOWN_SIGNAL`, exit 1). - Unrelated, seen on the way: in the Windows debug build, five other `parallel.test.ts` cases fail because the worker prints `ASSERTION FAILED: currentThreadIsHoldingAPILock()` from `JSC::VM::finalizeSynchronousJSExecution` (called from `run_as_worker` through `release_weak_refs`). The assertion is debug-only, this diff does not touch that code, and the release lanes in CI pass those cases. In this Linux container, `child_process.test.ts` has two unrelated failures: "should allow us to spawn in the default shell" (`$SHELL` is empty here) and "extra stdio pipes are not double-closed on GC" (20 debug+ASAN bun startups exceed the 5 s test timeout). "each worker has a unique JEST_WORKER_ID" in `parallel.test.ts` fails one run in three here, because a debug worker starts slower than the 200 ms the fixture sleeps. </details> <!-- robobun:evidence:begin --> --- **no test proof** · iteration 6 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/node/child_process/child_process.test.ts, test/js/bun/spawn/spawn-kill-signal.test.ts, test/js/bun/shell/shell-hang.test.ts, test/cli/test/parallel.test.ts, test/cli/run/run-propagate-sigkill.test.ts, test/cli/run/filter-workspace.test.ts, test/cli/install/bun-install-lifecycle-scripts.test.ts <!-- robobun:evidence:end -->
What's wrong
Bun keeps three disagreeing signal-name tables.
os.constants.signalsand thesubprocess.kill(name)path knowSIGSTKFLT,SIGPOLLandSIGPWR, butsignalNameToNumberMapinBunProcess.cpp(used byprocess.kill(pid, name)and theprocess.on(name)→sigactionwiring) does not. On Linux:The dangerous half is the listener side:
process.on("SIGSTKFLT", fn)succeeds,listenerCountreturns 1, but nosigactionis ever installed (theSigCgtbit in/proc/self/statusstays clear), so the first delivery of that signal kills the process to its default disposition with a JS handler attached:Node v26 accepts all three names from both APIs and the listener runs.
Cause
getSignalNames()/loadSignalNumberMap()inBunProcess.cppnever had entries forSIGSTKFLT,SIGPOLLorSIGPWR, sosignalNameToNumberMap->get(eventName)returned 0 for those names and the handler-install branch never executed, andprocess.kill's name lookup fell through toERR_UNKNOWN_SIGNAL.Two related bugs in the same code for aliased signal numbers (
SIGABRT/SIGIOTshare 6,SIGIO/SIGPOLLshare 29):Bun__onSignalForJSlooked up one canonical name per signal number fromsignalNumberToNameMapand emitted only that event, so a listener registered under the alias name never fired even though thesigactionwas installed. Node emits both.onDidChangeListenerskeyed the OS handler on the signal number but decided whether to uninstall it based only on the listener count of the event name being removed.process.on('SIGABRT', a); process.on('SIGIOT', b); process.removeListener('SIGABRT', a)restoredSIG_DFLfor signal 6 whilebwas still registered, so the next delivery killed the process.Fix
SIGSTKFLT,SIGPOLL,SIGPWRto thesignalNamesarray and to bothsignalNameToNumberMapandsignalNumberToNameMap, each under#ifdefso macOS/Windows are unaffected.Bun__onSignalForJSnow iteratessignalNameToNumberMapand emits the event for every name that resolves to the delivered signal number, so listeners registered under either alias fire with their own name as the first argument.onDidChangeListenersnow checks the listener count of every name that resolves to the same signal number before restoring the default disposition.process.on("SIGPWR", fn)resolves the name but still does not replace JSC's thread-suspend handler on Linux: the existingsignalNumber != g_wtfConfig.sigThreadSuspendResumeguard inonDidChangeListenersalready covers that.Verification
Four new tests in
test/js/node/process/process.test.js, each failing against basesrc/and passing with the fix:process.kill accepts every signal name in os.constants.signals(Linux) sends every name inos.constants.signalsto a nonexistent pid and asserts noERR_UNKNOWN_SIGNAL. Onmainit fails for exactlySIGSTKFLT,SIGPOLL,SIGPWR.process.on('SIGSTKFLT') installs a real handler and the listener runs(Linux) spawns a child that registers the listener, self-signals, and asserts the handler ran and the child exited 0.process.on fires listeners for every alias of a signal number(Linux) registers listeners for bothSIGPOLLandSIGIO, self-signals once, and asserts both fired with the correct name/number pair.removing one alias's listener keeps the handler installed for the other alias(POSIX) registersSIGABRTandSIGIOTlisteners, removes theSIGABRTone, self-signals, and asserts theSIGIOTlistener still runs and the child exits 0. Onmainthe child dies withsignalCode: SIGABRT.Also checked:
test/js/node/process/process-signal-listener-count.test.ts,test/js/node/process/process-on.test.ts,test/js/node/test/parallel/test-process-kill-pid.js, removing all aliases still restoresSIG_DFL, andBUN_JSC_validateExceptionChecks=1over both code paths.