Repository navigation
Process.run reads until stdout and stderr close, as Node's and Bun 1.4's spawnSync do - #1392
Merged
Merged
Conversation
…4's spawnSync do, so a descendant holding a pipe extends the wait up to the timeout Bun 1.4 made spawnSync drain its pipes to EOF (oven-sh/bun#33832), which the JS lane's Process.run inherits. The C lane now does the same: it reads until both pipes close, then reaps the child, all within the deadline. The exit descriptor (kqueue, pidfd) and the FIONREAD drain from #1054 go. A grandchild's late output now arrives, and the descendant checks in tests/io/process_run say so. Fixes #1343. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…n the exit descriptor once both pipes close Bun 1.3's spawnSync returns when the direct child exits, so the JS lane matched the new contract only on Bun 1.4+. process_run.js now runs the async Bun.spawn in a worker, which reads each pipe to its end on any version, while the main thread waits on Atomics.wait for the answer. The C lane polls the kqueue/pidfd exit descriptor again, but only after both pipes close, instead of checking waitpid every 1ms. `open`, which shadowed open(2), is now `reading`. tests/io/process_run checks a runaway descendant (`yes & echo hi`, Fail 27) and a child that closes its stdio and keeps running (timeout). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…a killed child, and can't hang the caller Bun's setTimeout turns a delay above 2^31-1 ms into 1 ms, so a U32 timeout near its max failed at once; the timer is clamped. Each call sends process.env, which the worker otherwise copies only when it starts. On timeout or EFBIG the worker awaits the killed child's exit before answering, as the C lane does. The caller waits at most the timeout plus 1s, then drops the worker and answers EIO. One channel and one flag, made with the worker, serve every call. tests/io/process_run checks the largest timeout. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Lorenzobattistela
approved these changes
Oct 9, 2026
This was referenced Oct 10, 2026
This was referenced Oct 13, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1343. Supersedes #1391.
Bun 1.4 changed
spawnSyncto read its pipes until they close, as Node's does (oven-sh/bun#33832). Bun treated the old behavior as a bug: output a grandchild wrote after the direct child exited was silently lost. The PR adds no option to keep it.Bend's contract ("waits for the direct child … a descendant holding an inherited pipe open does not extend the wait") was Bun 1.3's behavior, adopted for the C lane in #1054. This PR moves the contract to what Node, Bun 1.4 and, as far as I know, Python, Go and Rust do by default, and makes every lane follow it on any Bun version.
What changed:
process_run.c: reads until stdout and stderr both close, then reaps the child, all within the deadline. TheFIONREADdrain from fix(io): stop Process.run draining descendant pipes #1054 goes. The exit descriptor (kqueue/pidfd) stays, but it's polled only after both pipes close: before that, the child may already have exited, and the descriptor would stay readable and makepollspin. Without kqueue or pidfd, it checkswaitpidevery 50ms, as before.process_run.js: Bun 1.3'sspawnSyncreturns when the direct child exits, so the JS lanes no longer use it. A worker runs the asyncBun.spawn, which reads each pipe to its end on any Bun version. It enforces the timeout (clamped to 2³¹−1 ms, the mostsetTimeouttakes) and the combined output limit; on either, it kills the child, cancels both readers and waits for the child to exit, as the C lane does. Each call passes the currentprocess.env, which the worker would otherwise copy only when it starts. The main thread blocks onAtomics.wait(as long asspawnSyncblocked it) and takes the answer withreceiveMessageOnPort. The worker, its channel and the flag are made on the first call and reused; the worker isunref'd. If no answer comes within the timeout plus 1s (the worker failed to load or died), the call drops the worker and answersFailEIO instead of hanging. No FFI and nocomp.tschange, unlike JS Process.run parks on the child's pipes and exit, not Bun.spawnSync #1391.GUIDE.md: the call returns once the child exits and stdout and stderr close, so a descendant holding a pipe open delays it, up to the timeout.tests/io/process_run.bend:inherited pipe(sleep 3 & echo hi, now with a 300ms timeout) expects a timeout failure.descendant outputis nowprintf A; (sleep 0.2; printf B) & exit 0and expects"AB".runaway descendant(yes & echo hi) now expectsFail 27(output limit), the reverse of Process.run: a grandchild that keeps writing makes C answer Fail where JS answers Done #1051's fix. Itscontains_answerhelper is gone.closed stdio(exec >&- 2>&-; sleep 3, 300ms) expects a timeout: once the pipes close, the timeout still bounds the wait for the child to exit.largest timeout(/bin/echo hiwith a timeout of 4294967295 ms) expectsDone.Trade-off: a sloppily backgrounded process holding stdout (
cmd &in a shell one-liner) now runsProcess.runinto its timeout. That's the same footgun as in Node. Well-behaved daemons redirect their stdio.Bun version: none required. The JS lanes give the same answers on Bun 1.3.14 and 1.4.2, so the release and the cluster can stay on 1.3.14 for this.
Size (ttok, from the merge base):
process_run.c−196,process_run.js+480,process_run.bend+138,GUIDE.md+3; +425 in all.Checked (macOS arm64):
process_run(19 lines) andprocess_run_parallel: interpreter, emitted JS and native all pass on Bun 1.3.14 and on 1.4.2.process_runthrough abun build --compilebinary on 1.3.14 (the worker loads from a blob URL): passes.yesafterrunaway descendant: cancelling the readers closes the pipes.waitpidloop.process_run.jsin a harness, on both Bun versions: a child sees an env var set after the worker started; a child killed on timeout is reaped before the call answers; a worker that throws on load answersFail 5after the timeout plus 1s.bun gates/repo.ts: 50 / 50.Checked (Arch Linux x86_64, glibc 2.44):
process_runandprocess_run_parallel: interpreter, emitted JS and native all pass on Bun 1.3.14 and on 1.4.2. No strayyesafter.🤖 Generated with Claude Code