Repository navigation
Conversation
A host without Bun has no Worker and no Bun.spawn, so Process.run ended the run there with a raw ReferenceError before any answer. The node path runs on node:child_process.spawnSync, the semantics the C lane models: stdin fed, stdout and stderr read until they close, the exit code (signaled: 128 + the signal), a SIGKILL at the deadline, the spawn error handed back, and the combined output cap answered as EFBIG. The Bun worker path is unchanged.
Lorenzobattistela
left a comment
There was a problem hiding this comment.
Thanks @BaaRai for tracking this down! On main I get the same ReferenceError: Worker is not defined under Node, and with this branch process_run.bend passes 19/19 on Node 20 and 23. The Bun path and gates are unchanged.
Comparing the Node answers with Bun and C on some extra cases, the spawnSync path gives different results in a few of them:
- Child doesn't read all its stdin. With input over the pipe buffer, e.g.
Process.run("/usr/bin/head", ["-c", "3"], <100 KB>, 128, 3000)or/usr/bin/true, Node answersFail 32(EPIPE) and drops the child's status and output. Bun and C answerDone 0with"zzz". - Descendant holding stdin.
sh -c "sleep 2 <&0 >/dev/null 2>&1 & exit 4"with ~300 KB of input and a 500 ms timeout givesFail 60at the deadline on Node. Bun and C answerDone 4right away. - Combined cap. When stdout + stderr together pass
max_outputbut neither passes it alone (printf abc; printf def >&2; sleep 1; touch f, cap 5), the answer is still EFBIG, but Node lets the child keep running until it exits or the deadline, sofgets created. Bun and C kill it as soon as the sum goes over. - Small things: spawnSync reports the cap as
ENOBUFS(checked on Node 20 and 23), so theERR_CHILD_PROCESS_STDIO_MAXBUFFERbranch never runs;env: { ...process.env }is spawnSync's default already; and the comments are much longer than the rest ofeffs/.
Ideally Node would answer exactly like the Bun and C lanes, and this effect would keep a single implementation if possible. A second one doubles what has to stay in sync (process_run.js goes from ~800 to ~1,400 tokens).
One way to get there that I tried locally: build the worker from node:worker_threads (new Worker(code, { eval: true }) + parentPort) and have it use child_process.spawn, which both Bun and Node provide. Then the same worker serves both runtimes, and it matched Bun and C on all the cases above (process_run.js ~800 → ~870 tokens). It does change the Bun path from Bun.spawn to child_process.spawn, though, and that's the code from #1392, so @nicolas-abril, are you ok with that direction?
|
Closed: stale |
Fixes #1468.
Problem
Process.runon the Node host ended the run withReferenceError: Worker is not definedbefore any answer: the effect's worker path needs Bun's globalWorkerandBun.spawn, and a host without them has no way to run the child. Recent fixes verify the emitted standalone program on standalone Node too (#1446, #1450), so the gap was reachable from a practiced lane.Change
bend2/effs/process_run.js: after the shared validation, a host without Bun takes a newprocess_run_host, onnode:child_process.spawnSync, which is the semantics the C lane models (#1392): stdin fed, stdout and stderr read until they close (a descendant holding them extends the run), the exit code with signaled exits as 128 + the signal, a SIGKILL at the deadline, and the spawn error handed back as the errno.The output cap needed care, since spawnSync bounds each stream and the C lane bounds the sum:
maxBufferismax_output + 1per stream, so a stream past it alone puts the sum past the combined cap, and the sum is checked after the read; the answer isEFBIGexactly when the C lane's combined cap says so. The interim buffer is at most twice the cap.ENOBUFS(v22 here; the older code isERR_CHILD_PROCESS_STDIO_MAXBUFFER, kept for older hosts), and a flood that a descendant keeps past the deadline may surface asETIMEDOUTwith the partial buffers attached, so any error whose buffered sum is past the cap answersEFBIG: the cap fired first either way.The Bun worker path is unchanged behind
typeof Bun === "undefined".Verification
On Linux x86_64 (WSL Debian 12), main at 5e70819 plus this branch:
tests/io/process_run.bend, the permanent regression, emitted standalone (-o out.js) and run on every host. Before the fix Node ended the run at the first call; after:bun out.js)node out.js)bend tests/io/process_run.bend)The Node run covers every row: stdin feeding, literal argv, exit and stderr, the at/over/combined cap rows (EFBIG), timeout (ETIMEDOUT), a missing executable (ENOENT), invalid limit and timeout (EINVAL), a NUL argument, a signal exit (143), SIGPIPE default, an inherited pipe past the deadline, descendant output after the child exits, a runaway descendant past the cap (this row is what pinned the ENOBUFS/flood rule above), closed stdio and the largest timeout.
tests/io/process_run_parallel.bendanswers True on the interpreted, JS and C lanes.Repo gate: 52/54 with and without this change. The two FAILs are the capped files
bend2/comp.ts(64070) andbend2/bendtt.lean(64192) under this host'sttok(pip), files this PR does not touch; the same two FAILs appear on unmodified main here, and the maintainers' counter reports 63,995 forcomp.ts(#1250), so the difference is the counter, not the tree.No new test file: the gate runs the JS lane under Bun, where this path is unreachable (Bun keeps the worker path); the Node evidence above stands in for it, as in #1450.