Repository navigation
JS Process.run parks on the child's pipes and exit, not Bun.spawnSync - #1391
Closed
nicolas-abril wants to merge 3 commits into
Closed
nicolas-abril wants to merge 3 commits into
nicolas-abril wants to merge 3 commits into
Conversation
…, so a descendant holding a pipe no longer runs it into the timeout on Bun 1.4, and other computations run meanwhile Bun 1.4's spawnSync waits for the pipes' EOF, as Node's does, not for the direct child. process_run.js now follows process_run.c over bun:ffi: posix_spawnp on close-on-exec pipes, then io_park_on over stdin, stdout, stderr and an exit descriptor (pidfd, or a kqueue on macOS), draining only what is buffered once the child is reaped. io_park_on takes a list of [fd, out] pairs in place of fd, and wakes on the first ready. Fixes #1343. Supersedes #1371, whose closed-stdin regression this keeps. Co-Authored-By: Mansurshakh Japarov <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
nicolas-abril
marked this pull request as draft
October 7, 2026 17:38
…f FIONREAD, and needs glibc 2.34 as the C lane does Drops the variadic ioctl and its Apple arm64 padding, and the optional addclosefrom_np binding. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ld that enlarged its pipe loses no output A macOS pipe holds 64KB; a Linux one reports its size through F_GETPIPE_SZ, which io_sys's fcntl reads. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Collaborator
Author
|
Closing in favor of #1392, which makes every lane read until stdout and stderr close (Bun 1.4's spawnSync behavior) on any Bun version, without FFI or a comp.ts change. |
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 #1371.
Bun 1.4 changed
spawnSyncto wait for the child's pipes to close, as Node'sspawnSyncalways has, instead of for the child to exit. A background grandchild holding stdout open (sh -c "sleep 3 & echo hi") now runsProcess.runinto its timeout. On Bun 1.3.14, main passes; on 1.4.2 it failsinherited pipeanddescendant output. The 1.4 release notes don't mention the change.No
spawnSynccall gives the documented behavior, and the JS runtime's loop is synchronous, so Bun's asyncspawncallbacks never run. The JS lane therefore does whatprocess_run.cdoes, overbun:ffi, but parks on the loop instead of blocking it.What changed:
process_run.js:posix_spawnpon close-on-exec pipes, moved above fd 2, with SIGPIPE back at its default.yes &) can't keep the call from seeing the exit. Once the direct child is reaped, it reads at most each pipe's capacity more (what it could hold at the exit) and answers: 64KB on macOS,F_GETPIPE_SZon Linux.posix_spawn_file_actions_addclosefrom_np).io_park_on(comp.ts, +22 tokens): in place offd, it also takes a list of[fd, out]pairs and wakes on the first one ready. Waiting stays on the oneselectloop: no epoll, and no kqueue beyond the exit notification. Existing callers are unchanged.GUIDE.mdandEFFECTS.mdare updated.Compared to #1371:
pollloop.waitpidevery 50ms.ECHILD, so it can't hit a reused pid.It keeps #1371's closed-stdin regression test (its author is credited as co-author).
New test:
process_run_besidechecks thatmainprints while a forkedProcess.runchild is still running. Main's code fails it: the order flips.Checked (macOS arm64):
process_run,process_run_parallel,process_closed_stdinandprocess_run_besidepass in the interpreter, emitted JS and native lanes.True) and the two new tests.cat; a child that ignores 3MB of stdin (EPIPE);yesover the limit (Fail 27); a child that closes its pipes and exits 200ms later; 64KB on each of stdout and stderr written just before exit, and 500KB.bun gates/repo.ts: 50 / 50.Not checked:
addclosefrom_np,F_GETPIPE_SZ(1032) andO_NONBLOCK0x800 are only checked against headers.comp.tsis at 63,997 of its 64,000-token cap.🤖 Generated with Claude Code