Skip to content

child_process: report SIGSTKFLT instead of 'SIG16' on child exit - #33775

Closed
robobun wants to merge 2 commits into
mainfrom
farm/cbc5b4a3/fix-sigstkflt-signal-name
Closed

robobun wants to merge 2 commits into
mainfrom
farm/cbc5b4a3/fix-sigstkflt-signal-name

Conversation

@robobun

@robobun robobun commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Problem

On Linux, when a child process is killed by signal 16 (SIGSTKFLT), Bun reports the signal name as the invented string "SIG16" in the exit/close event argument and in subprocess.signalCode. Node.js reports "SIGSTKFLT".

import { spawn } from "node:child_process";
const c = spawn("/bin/sleep", ["5"], { stdio: "ignore" });
setTimeout(() => process.kill(c.pid, 16), 60);
c.on("exit", (code, signal) => console.log(JSON.stringify({ code, signal, signalCode: c.signalCode })));
// node:  {"code":null,"signal":"SIGSTKFLT","signalCode":"SIGSTKFLT"}
// bun:   {"code":null,"signal":"SIG16","signalCode":"SIG16"}

"SIG16" is not a real signal name. It appears nowhere in POSIX, Node's docs, or Bun's own os.constants.signals (which correctly has SIGSTKFLT === 16). Code that switches on documented signal names (process managers, lifecycle runners, signal-exit-style libraries) receives an impossible value and falls through.

It was also internally inconsistent: child.kill("SIGSTKFLT") accepts the name and delivers signal 16, then reports the resulting death as "SIG16".

Cause

The for_each_signal! X-macro in src/bun_core/Global.rs, which is the single source of truth for SIGNAL_NAMES, SignalCode, and from_name, had a placeholder entry SIG16 = 16 instead of SIGSTKFLT = 16. No other numeric placeholders exist in the table, and nothing in the tree references SignalCode::SIG16 by name.

Fix

Rename the entry to SIGSTKFLT. All downstream consumers (exit-status naming, subprocess.signalCode, bun_sys::SignalCode associated consts, from_name) are generated from this macro.

Verification

New test in test/js/node/child_process/child_process.test.ts (Linux-only; SIGSTKFLT is Linux-specific) asserts the round trip: child.kill("SIGSTKFLT") followed by exit event reporting {signal: "SIGSTKFLT", signalCode: "SIGSTKFLT"}.

Before / after

Before (bun 1.4.0):

expect(received).toEqual(expected)
  {
    code: null,
-   signal: "SIGSTKFLT",
-   signalCode: "SIGSTKFLT",
+   signal: "SIG16",
+   signalCode: "SIG16",
  }

After:

(pass) child killed by SIGSTKFLT reports 'SIGSTKFLT', not 'SIG16'

The for_each_signal! X-macro that generates SIGNAL_NAMES and SignalCode
had a placeholder entry SIG16 = 16 instead of SIGSTKFLT = 16. As a
result, a child killed by signal 16 was reported as 'SIG16' in the
exit/close event signal argument and in subprocess.signalCode, while
Node.js reports 'SIGSTKFLT' and Bun's own os.constants.signals already
maps SIGSTKFLT to 16.
@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:04 PM PT - Jul 8th, 2026

❌ @robobun, your commit 639fb28 has 4 failures in Build #70602 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 33775

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

bun-33775 --bun

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a59c59cd-9e2c-41bc-8168-d78c473883ac

📥 Commits

Reviewing files that changed from the base of the PR and between 332f744 and 318fffb.

📒 Files selected for processing (2)
  • src/bun_core/Global.rs
  • test/js/node/child_process/child_process.test.ts

Walkthrough

This PR fixes an incorrect signal name in the for_each_signal! X-macro, renaming the generated SignalCode variant for signal number 16 from SIG16 to SIGSTKFLT. A new Linux-only regression test verifies correct signal reporting when killing a child process with SIGSTKFLT.

Changes

SIGSTKFLT naming fix

Layer / File(s) Summary
Correct signal 16 variant name and add regression test
src/bun_core/Global.rs, test/js/node/child_process/child_process.test.ts
The for_each_signal! macro entry for signal 16 is renamed from SIG16 to SIGSTKFLT, changing the generated SignalCode enum variant and name table entry; a new Linux-only test spawns a sleep process, kills it with SIGSTKFLT, and asserts the exit event reports signal and signalCode as "SIGSTKFLT".

Possibly related PRs

  • oven-sh/bun#30982: Also touches SIGNAL_NAMES/SignalCode generation, using the same signal name table for validation error messages in kill().
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main child_process signal reporting fix.
Description check ✅ Passed The description clearly explains the problem, cause, fix, and verification, though it uses different headings than the template.
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.

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

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — one-token rename in the signal table (SIG16 → SIGSTKFLT) with a solid Linux-gated regression test.

Extended reasoning...

Overview

This PR changes exactly one token in src/bun_core/Global.rs: the for_each_signal! X-macro entry SIG16 = 16 becomes SIGSTKFLT = 16. All consumers of signal names (SIGNAL_NAMES, the SignalCode enum, from_raw/from_name, and bun_sys::SignalCode associated consts) are generated from this macro, so the rename propagates automatically. A Linux-only regression test in test/js/node/child_process/child_process.test.ts round-trips child.kill("SIGSTKFLT") and asserts the exit event reports {signal: "SIGSTKFLT", signalCode: "SIGSTKFLT"} instead of the invented "SIG16".

I grepped the tree: SIG16 no longer appears anywhere in src/ (only in the new test's comment/title as historical context), and SIGSTKFLT was already the spelling used by os.constants.signals, ProcessBindingConstants.cpp, and NodeConstantsModule.h — this fix brings the signal-name reporting path into agreement with the rest of the codebase and with Node.js.

Security risks

None. This is a static string-table entry rename. No parsing of untrusted input, no auth/crypto/permission surface, no memory or lifetime changes.

Level of scrutiny

Low. The change is a single identifier in a data table whose purpose is explicitly to be the sole source of truth for signal names. SIG16 was clearly a placeholder (the only numeric-suffix entry in the table), and nothing referenced it by name. The behavioral surface is limited to the string reported for signal 16 on child exit — moving from a made-up value to the POSIX/Node-documented one is strictly a compatibility improvement.

Other factors

The test follows repo conventions well: gated with it.if(isLinux) (SIGSTKFLT is Linux-specific), wires error to reject, awaits the spawn event before killing, and asserts the full {code, signal, signalCode} object. The os import addition is clean. No outstanding reviewer comments; CI build was triggered. This is the kind of mechanical data fix that doesn't need human review.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — one-token rename in the signal name table with a matching regression test.

Extended reasoning...

Overview

This PR renames a single entry in the for_each_signal! X-macro in src/bun_core/Global.rs from the placeholder SIG16 = 16 to the correct SIGSTKFLT = 16, and adds a Linux-only regression test in test/js/node/child_process/child_process.test.ts that verifies child.kill("SIGSTKFLT") round-trips to signal === "SIGSTKFLT" on the exit event.

Security risks

None. This is a string-constant rename in a static lookup table; no untrusted input handling, auth, crypto, or permissions logic is touched.

Level of scrutiny

Low. The source change is a one-token data fix in a generated-from-macro table. I confirmed via grep that nothing in src/ references SignalCode::SIG16 or the string "SIG16", so the rename cannot break any consumer. SIGSTKFLT already appears in NodeConstantsModule.h and ProcessBindingConstants.cpp with value 16, so this brings the Rust table into agreement with the existing C++ constants and with Node.js. The macro comment explicitly states it is the single source of truth for SIGNAL_NAMES, SignalCode, and from_name, so all downstream consumers pick up the correction automatically.

Other factors

The new test is well-constructed: gated on isLinux (SIGSTKFLT is Linux-specific), wires error to reject, awaits the spawn event before killing, and asserts an exact object equality on {code, signal, signalCode}. It follows the neighboring test patterns in the file. Neither modified file is covered by CODEOWNERS. The bug-hunting system found no issues, and there are no outstanding reviewer comments.

@robobun

robobun commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI is red on unrelated flakes; the diff itself is green.

  • Build 70584: test/js/bun/http/proxy-stress-concurrent.test.ts on macOS 14 x64, one of 1200 concurrent HTTPS proxy requests failed.
  • Build 70602: test/js/sql/postgres-binary-array-bounds.test.ts on Windows 2019 x64-baseline, ERR_POSTGRES_CONNECTION_REFUSED from the mock server.

Neither build flagged test/js/node/child_process/child_process.test.ts on any lane, and the new SIGSTKFLT test is Linux-only. This PR's only source change is a one-token rename in the for_each_signal! macro, which cannot affect HTTP proxying or Postgres connection handling. Ready for review.

@robobun

robobun commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #39970, which renames slot 16 to SIGSTKFLT as part of mapping signal numbers per platform, and carries a test for it.

@robobun robobun closed this Aug 21, 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