Repository navigation
Description
ROOT CAUSE CORRECTION (deep-dived on main @ 892b1dab — the original analysis below is preserved but its mechanism was wrong):
The panic is not about signal delivery during streaming at all. It is:
Bun.Subprocess.kill(signalName) maps signal names with the LINUX signal-number table on macOS
src/bun_core/Global.rs — the canonical for_each_signal! X-macro that generates SignalCode — hardcodes Linux numbers unconditionally:
SIGBUS = 7, SIGFPE = 8, SIGKILL = 9, SIGUSR1 = 10, SIGSEGV = 11, SIGUSR2 = 12, ...
SIGCHLD = 17, SIGCONT = 18, SIGSTOP = 19, SIGTSTP = 20, ... SIGIO = 29, SIGPWR = 30, SIGSYS = 31On Darwin (<sys/signal.h>): SIGUSR1=30, SIGUSR2=31, SIGBUS=10, SIGSYS=12, SIGURG=16, SIGSTOP=17, SIGTSTP=18, SIGCONT=19, SIGCHLD=20, SIGIO=23, SIGINFO=29, SIGEMT=7 — everything outside 1–6, 8, 9, 11, 13–15, 21–22, 24–28 diverges.
subprocess.kill("SIGUSR1") → FromJsEnum for bun_sys::SignalCode (src/jsc/lib.rs) → signal_code::from_name → 10 → kill(child, 10) = SIGBUS on macOS. Bun's crash reporter in the child catches the externally-sent SIGBUS with si_addr = 0 and prints panic: Bus error at address 0x0 — which is exactly the "panic" in my original report. The child's JS SIGUSR1 handler "never ran" because SIGUSR1 was never sent. The streaming response was a red herring (it merely made the child a Bun process someone wanted to signal gracefully).
Discriminating evidence (macOS 15.7.7 arm64, reproduces on 1.3.14 stable AND 1.4.0 canary 2892b1da)
A bash child that traps everything, signalled each way:
Subprocess.kill("SIGUSR1") → child saw: GOT-BUS ← Linux 10 = macOS SIGBUS
Subprocess.kill("SIGUSR2") → child saw: GOT-SYS ← Linux 12 = macOS SIGSYS
Subprocess.kill(30) → child saw: GOT-USR1 ← numeric passes through correctly
Subprocess.kill("SIGTERM") → child saw: GOT-TERM ← 15 on both platforms, works
process.kill(pid, "SIGUSR1") → child saw: GOT-USR1 ← process.kill maps correctly (separate path)
node:child_process .kill("SIGUSR1") → GOT-USR1 ← node-compat maps correctly (separate path)
And shell kill -USR1 <bun pid> is handled perfectly fine by process.on("SIGUSR1") even mid-stream — confirming signal delivery was never the bug.
Reverse direction is broken by the same table
A child killed by a real SIGUSR1 (/bin/kill -30) is reported as:
proc.signalCode === "SIGPWR" // Linux name for 30; should be "SIGUSR1"Worse cases in the same table
subprocess.kill("SIGCHLD")sends 17 = macOS SIGSTOP → silently stops the child instead of a no-op notification signal."SIGSTOP"sends 19 = macOS SIGCONT,"SIGCONT"sends 18 = macOS SIGTSTP — stop/continue are inverted-ish on macOS.- Everything flowing through
SignalCodeinherits this:Bun.spawn/Subprocess.kill, the shell's kill builtin (src/runtime/shell/subproc.rs), lifecycle script termination (src/install/lifecycle_script_runner.rs), exit-signal naming/+128exit codes, andbun test's reporting.
Fix
Make the for_each_signal! table platform-conditional (#[cfg(target_vendor = "apple")] Darwin table verified against the SDK's <sys/signal.h>, existing table for Linux/Windows), and cfg the platform-only names (SIGPWR ⟷ SIGEMT/SIGINFO) in SignalCode::description. Every consumer (from_name, from_raw, SIGNAL_NAMES, to_exit_code, the JS FromJsEnum path) regenerates from the macro, fixing both directions at once. PR incoming.
Original report (mechanism superseded by the analysis above — the observations were real, the attribution to signal delivery/streaming was wrong)
What version of Bun is running?
Reproduced on both 1.3.14 (latest stable, 0d9b296a) and 1.4.0 canary (2892b1da).
What platform is your computer?
macOS 15.7.7 (Darwin 24.6.0), Apple Silicon (arm64).
What steps can reproduce the bug?
Deliver any signal that has a JS process.on(...) handler installed to a Bun process while an HTTP response body is streaming. The process panics with Bus error at address 0x0. The handler body is irrelevant — an empty () => {} handler panics identically, and the handler never runs.
Self-contained repro (server + client in one file):
// bun-signal-stream-panic.ts — run: bun bun-signal-stream-panic.ts
const PORT = 49771;
if (process.argv[2] === "server") {
const enc = new TextEncoder();
Bun.serve({
port: PORT,
fetch() {
let t: ReturnType<typeof setInterval>;
return new Response(
new ReadableStream<Uint8Array>({
start(c) {
t = setInterval(() => c.enqueue(enc.encode("data: tick\n\n")), 150);
},
cancel() {
clearInterval(t);
},
}),
{ headers: { "content-type": "text/event-stream" } },
);
},
});
process.on("SIGUSR1", () => console.log("server: signal handler ran")); // never prints — panic first
console.log("server: ready");
setTimeout(() => process.exit(0), 10_000);
} else {
const proc = Bun.spawn({
cmd: [process.execPath, process.argv[1]!, "server"],
stdout: "inherit",
stderr: "inherit",
});
await Bun.sleep(400);
const res = await fetch(`http://127.0.0.1:${PORT}/`);
const reader = res.body!.getReader();
await reader.read(); // the stream is live
console.log("client: stream is live → sending SIGUSR1 to the server");
proc.kill("SIGUSR1"); // ← server panics: "Bus error at address 0x0"
const died = await Promise.race([
proc.exited.then((code) => `RESULT: server DIED (exit ${code}) — panic reproduced`),
Bun.sleep(2000).then(() => null),
]);
console.log(died ?? "RESULT: server survived the signal — NO panic");
proc.kill("SIGKILL");
process.exit(0);
}What is the expected behavior?
The signal handler runs; the streaming response keeps flowing. (This is the standard graceful-shutdown pattern: process.on("SIGTERM", drainAndExit) on a server that serves SSE.)
What do you see instead?
server: ready
client: stream is live → sending SIGUSR1 to the server
panic(main thread): Bus error at address 0x0
RESULT: server DIED (exit 133) — panic reproduced
Every in-flight connection is RST. The handler's console.log never prints — the crash happens during signal delivery, before the JS handler executes.
Additional information
Variables isolated while root-causing this (each verified on the same machine):
- Handler body irrelevant: an empty handler, a handler that only logs, and a handler that calls
server.stop(false)all panic identically. Deferring work viasetTimeout(..., 1)inside the handler doesn't help — the panic precedes the handler. - No signal ⇒ no panic: the identical drain logic (
server.stop(false)+ waiting for the body to finish) run from a timer callback works perfectly — listener closes instantly, the in-flight stream runs to completion. - No active stream ⇒ no panic: with handlers installed but no streaming response in flight, signals are handled normally.
- Both
SIGUSR1andSIGTERMreproduce (any handled signal, apparently). Signal sent viaSubprocess.kill()orkill(1)from a shell — same result. - Exit code 133 on 1.3.14, 138 on 1.4.0 canary.
Decoded crash (bun.report, canary): us_loop_run_bun_tick (epoll_kqueue.c:483) → auto_tick_active (VirtualMachine.rs:2265) → holdAPILock (bindings.cpp:4754) → RunCommand::boot — Bus error at 0x0 in the event loop.
Crash reports:
- 1.3.14: https://bun.report/1.3.14/Ma10d9b296AgggoC_uptmLm2//iB+tqwH28stU24/zU2rtjU22nzT+mzvT2wuvT__A4AA
- 1.4.0 canary: https://bun.report/1.4.0/Ma2892b1daAgggoC_22lvGuw65Lmlq/Cmkn/C+hn/C+y2Ju/slFum0Dm86Cu+qB2se__A4AA
Impact: any server that installs a SIGTERM handler for graceful shutdown and serves SSE/streaming responses crashes on shutdown signals, RSTing all in-flight streams — we hit this as launchd's SIGTERM killing live Anthropic API streams mid-response in a proxy daemon. Workaround we shipped: install no signal handlers in the serving process and deliver lifecycle commands over a loopback HTTP admin channel instead.
Possibly adjacent but different triggers: #31159 (ReadableStream finalizer segfault, Linux, no signals), #21524 (macOS node:net crash).
Activity
[-]panic(main thread): Bus error at 0x0 — delivering a signal with a process.on handler installed while an HTTP response is streaming (macOS arm64, 1.3.14 + 1.4.0 canary)[/-][+]Subprocess.kill(signalName) uses Linux signal numbers on macOS — "SIGUSR1" delivers SIGBUS (child "panics"), signalCode reporting also wrong[/+]hoang17 commentedon Jul 23, 2026
Update: deep-dived this on
main(892b1dab) and corrected the title/body — the real root cause is that the canonical signal table (for_each_signal!insrc/bun_core/Global.rs) hardcodes Linux signal numbers, soSubprocess.kill("SIGUSR1")sends 10 = SIGBUS on macOS (the "panic" was the child's crash reporter catching that externally-sent SIGBUS,si_addr=0).process.killandnode:child_processhave separate, correct mappings — only theSignalCodeconsumers (Bun.spawn kill, shell, lifecycle scripts, exit-signal naming) are affected. Fix PR incoming: platform-conditional table verified against the macOS SDK.fix(spawn): use Darwin signal numbers on macOS — "SIGUSR1" was delive…
fix(spawn): use Darwin signal numbers on macOS — "SIGUSR1" was delive…
test(hot): replace the entrypoint while the --hot process is stopped
test(hot): replace the entrypoint while the --hot process is stopped
test(hot): replace the entrypoint while the --hot process is stopped
test(hot): replace the entrypoint while the --hot process is stopped
kitlangton commentedon Aug 28, 2026
Confirmed on macOS 26.5.1 arm64 with released Bun 1.3.14 (
0d9b296a) and 1.4.0 (34cbb9a40). With a child listening for both signals:Without a SIGBUS handler, the first call crashes the child with
Bus error at address 0x0./bin/kill -USR1works correctly too.spawn: name exit signals and send named signals with the platform's n…
toolchain: bun 1.4.2 to 1.4.4