Skip to content

process: accept SIGSTKFLT/SIGPOLL/SIGPWR by name and fire aliased signal listeners - #33776

Closed
robobun wants to merge 5 commits into
mainfrom
farm/5160ebe8/process-signal-name-tables
Closed

robobun wants to merge 5 commits into
mainfrom
farm/5160ebe8/process-signal-name-tables

Conversation

@robobun

@robobun robobun commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator

What's wrong

Bun keeps three disagreeing signal-name tables. os.constants.signals and the subprocess.kill(name) path know SIGSTKFLT, SIGPOLL and SIGPWR, but signalNameToNumberMap in BunProcess.cpp (used by process.kill(pid, name) and the process.on(name) → sigaction wiring) does not. On Linux:

import { spawn } from "node:child_process";
const c = spawn("/bin/sleep", ["5"]);
process.kill(c.pid, "SIGSTKFLT"); // throws ERR_UNKNOWN_SIGNAL
c.kill("SIGSTKFLT");              // delivers signal 16

The dangerous half is the listener side: process.on("SIGSTKFLT", fn) succeeds, listenerCount returns 1, but no sigaction is ever installed (the SigCgt bit in /proc/self/status stays clear), so the first delivery of that signal kills the process to its default disposition with a JS handler attached:

listener child: {"status":null,"signal":"SIG16","stdout":"listeners: 1"}   // DIED, handler never ran

Node v26 accepts all three names from both APIs and the listener runs.

Cause

getSignalNames() / loadSignalNumberMap() in BunProcess.cpp never had entries for SIGSTKFLT, SIGPOLL or SIGPWR, so signalNameToNumberMap->get(eventName) returned 0 for those names and the handler-install branch never executed, and process.kill's name lookup fell through to ERR_UNKNOWN_SIGNAL.

Two related bugs in the same code for aliased signal numbers (SIGABRT/SIGIOT share 6, SIGIO/SIGPOLL share 29):

  • Bun__onSignalForJS looked up one canonical name per signal number from signalNumberToNameMap and emitted only that event, so a listener registered under the alias name never fired even though the sigaction was installed. Node emits both.
  • onDidChangeListeners keyed 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) restored SIG_DFL for signal 6 while b was still registered, so the next delivery killed the process.

Fix

  • Add SIGSTKFLT, SIGPOLL, SIGPWR to the signalNames array and to both signalNameToNumberMap and signalNumberToNameMap, each under #ifdef so macOS/Windows are unaffected.
  • Bun__onSignalForJS now iterates signalNameToNumberMap and 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.
  • The uninstall branch in onDidChangeListeners now 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 existing signalNumber != g_wtfConfig.sigThreadSuspendResume guard in onDidChangeListeners already covers that.

Verification

Four new tests in test/js/node/process/process.test.js, each failing against base src/ and passing with the fix:

  • process.kill accepts every signal name in os.constants.signals (Linux) sends every name in os.constants.signals to a nonexistent pid and asserts no ERR_UNKNOWN_SIGNAL. On main it fails for exactly SIGSTKFLT, 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 both SIGPOLL and SIGIO, 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) registers SIGABRT and SIGIOT listeners, removes the SIGABRT one, self-signals, and asserts the SIGIOT listener still runs and the child exits 0. On main the child dies with signalCode: 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 restores SIG_DFL, and BUN_JSC_validateExceptionChecks=1 over both code paths.

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.
@github-actions github-actions Bot added the claude label Jul 8, 2026
@robobun

robobun commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 3:41 PM PT - Jul 8th, 2026

❌ @robobun, your commit bc42433 has 2 failures in Build #70623 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 33776

That installs a local version of the PR into your bun-33776 executable, so you can run:

bun-33776 --bun

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Found 1 issue this PR may fix:

  1. signal-exit package misbehaves with Bun (node compatibility) #12918 - The signal-exit package registers listeners on signal aliases like SIGIOT; this PR fixes Bun__onSignalForJS to dispatch to all alias names for a given signal number, so those listeners actually fire.

If this is helpful, copy the block below into the PR description to auto-close this issue on merge.

Fixes #12918

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 4 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 168b49bb-1bc0-4367-a7d5-0928832bfe79

📥 Commits

Reviewing files that changed from the base of the PR and between 76c7622 and bc42433.

📒 Files selected for processing (2)
  • src/jsc/bindings/BunProcess.cpp
  • test/js/node/process/process.test.js

Walkthrough

This 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.

Changes

Signal Alias Handling

Layer / File(s) Summary
Signal name/number map extensions
src/jsc/bindings/BunProcess.cpp
Adds SIGSTKFLT, SIGPOLL, and SIGPWR to getSignalNames, signalNameToNumberMap, and loadSignalNumberMap, with increased reserved capacity from 31 to 35.
Multi-alias signal dispatch and listener map
src/jsc/bindings/BunProcess.cpp
Bun__onSignalForJS now iterates the name→number map to emit an event per matching alias instead of a single number→name lookup; the listener-side signalNumberToNameMap gains matching entries and increased capacity.
Signal handling tests
test/js/node/process/process.test.js
Adds node:os import and Linux-only tests covering process.kill across all os.constants.signals names, plus process.on handling for SIGSTKFLT and SIGPOLL/SIGIO aliases.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the core change: adding support for SIGSTKFLT, SIGPOLL, and SIGPWR signal names and alias listener dispatch.
Description check ✅ Passed The description covers the change and verification, though it uses custom headings instead of the template’s exact sections.

Comment @coderabbitai help to get the list of available commands.

@robobun

robobun commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

Checked #12918: the onExit called with exit code 0 miss there is about signal-exit monkeypatching process.reallyExit/process.emit, which bun's exit path doesn't route through. That isn't touched by this PR, so not linking it.

Comment thread src/jsc/bindings/BunProcess.cpp Resolved
robobun and others added 2 commits July 8, 2026 18:58
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.
Comment thread src/jsc/bindings/BunProcess.cpp Resolved
robobun added 2 commits July 8, 2026 19:24
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.
@robobun

robobun commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

The diff is ready. Both CI runs (builds 70605 and 70623) passed the four new tests in test/js/node/process/process.test.js on every lane; the remaining failures are unrelated flakes (napi_wrap lifetime on Windows, postgres connection refused on Windows aarch64, proxy-stress and no-orphans timeouts on macOS, install/hot-reload Windows flakes). None of them touch BunProcess.cpp or signal handling.

@robobun

robobun commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@robobun robobun closed this Sep 13, 2026
dylan-conway pushed a commit that referenced this pull request Sep 20, 2026
…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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant