You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Keep JS Process.run bounded by the direct child - #1371
Replace Bun.spawnSync's inherited-pipe lifecycle with synchronous POSIX spawn/poll/waitpid through Bun FFI, matching the existing native contract. Feed stdin and capture both streams concurrently, enforce the combined byte limit and a monotonic deadline, reap the direct child, then drain only already-buffered output. Descendants retaining the pipes do not extend the wait. Timeout/output failures kill and reap the child and close all parent descriptors.
Keep literal argv, spawn errno, signal exit codes and child SIGPIPE defaults. Relocate pipe fds below 3 before setting up child stdio. Handle Darwin arm64's stack-based variadic ABI for fcntl and ioctl. No expectation in the existing process fixture is relaxed; add a real closed-parent-stdin regression with JS/C twins.
Verification on Linux (Bun 1.3.13, Clang 22):
Existing 16-check process fixture: every check True in source IO CLI, emitted JS and native CPU binary.
Existing parallel process fixture: True.
Closed-parent-stdin regression: 0:payload: on JS and native with 1/4 threads.
Real-process stress: 100 timeouts under forced GC, exact 4,000-byte environment value preserved, stable open-fd count, no unreaped direct children.
Repository gate: PASS: 50 / 50 including staged fixtures.
Clang arm64-apple-darwin ABI probe verifies the padded FFI call places ioctl's pointer on the same stack slot as a real variadic call. This is code-generation evidence, not a macOS runtime test.
MacOS runtime verification remains for the project CI/maintainer; no Mac, GPU or mini-cluster run is claimed. No native runtime, gates/caps, GUIDE or release-changelog changes.
Rechecked the combined fixes against upstream 237c7226 / Bend 2.0.36. The source IO CLI and emitted JS still pass every existing Process.run check (16/16 True), including inherited pipes and descendant output; the closed-parent-stdin regression prints 0:payload:. The unchanged repository gate passes 50/50. The macOS limitation remains as documented: arm64 variadic stack placement was checked with Clang code generation, not on macOS hardware.
Thanks for the investigation and the closed-stdin regression test. Closing in favor of #1391, which takes the same bun:ffi approach but parks on the event loop through io_park_on instead of running its own poll loop, wakes on the child's exit fd (pidfd/kqueue) instead of polling waitpid every 50ms, and covers the review points (8KB retention per chunk, argv/env lifetime, ECHILD, poll timeout rounding). Your closed-stdin test is kept there, with you credited as co-author.
To expand on why: both PRs take the same bun:ffi approach, since Bun 1.4's spawnSync waits for the pipes' EOF, like Node's, so no spawnSync call can keep the documented behavior. The differences:
The rest of the program keeps running. This PR's own poll loop blocks the whole JS event loop until the child exits or times out, so every socket, sleep and channel stalls meanwhile. JS Process.run parks on the child's pipes and exit, not Bun.spawnSync #1391 parks on the loop, as the native lane does. Its process_run_beside test checks this.
It notices the exit right away. Without an exit fd, the exit is only seen by polling waitpid every 50ms, which adds up to 50ms per call in exactly the descendant-holds-the-pipe case.
Bugs fixed:
each small read kept a whole 8KB buffer alive, so a child printing short lines could hold hundreds of MB while under maxOutput;
nothing kept the argv/env buffers alive while the child started;
after ECHILD it could SIGKILL a reused pid;
the truncated poll timeout spun the CPU in the last millisecond before the deadline.
Thanks for the detailed review and for preserving the closed-stdin regression with co-author credit in #1391. Understood the event-loop parking and exit-fd differences; I will leave this superseded implementation closed.
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
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.
Closes #1343.
Replace Bun.spawnSync's inherited-pipe lifecycle with synchronous POSIX spawn/poll/waitpid through Bun FFI, matching the existing native contract. Feed stdin and capture both streams concurrently, enforce the combined byte limit and a monotonic deadline, reap the direct child, then drain only already-buffered output. Descendants retaining the pipes do not extend the wait. Timeout/output failures kill and reap the child and close all parent descriptors.
Keep literal argv, spawn errno, signal exit codes and child SIGPIPE defaults. Relocate pipe fds below 3 before setting up child stdio. Handle Darwin arm64's stack-based variadic ABI for fcntl and ioctl. No expectation in the existing process fixture is relaxed; add a real closed-parent-stdin regression with JS/C twins.
Verification on Linux (Bun 1.3.13, Clang 22):
Truein source IO CLI, emitted JS and native CPU binary.True.0:payload:on JS and native with 1/4 threads.PASS: 50 / 50including staged fixtures.arm64-apple-darwinABI probe verifies the padded FFI call places ioctl's pointer on the same stack slot as a real variadic call. This is code-generation evidence, not a macOS runtime test.MacOS runtime verification remains for the project CI/maintainer; no Mac, GPU or mini-cluster run is claimed. No native runtime, gates/caps, GUIDE or release-changelog changes.