Skip to content

fix(io): Process.run's worker loads its modules on Node before 20.16 too - #2226

Merged
Lorenzobattistela merged 2 commits into
bendlang:mainfrom
rbmr:fix/process-run-old-node
Nov 23, 2026
Merged

Lorenzobattistela merged 2 commits into
bendlang:mainfrom
rbmr:fix/process-run-old-node

Conversation

@rbmr

@rbmr rbmr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Since #1842 the Process.run worker loads its modules with
process.getBuiltinModule, which Node added in v22.3.0 and v20.16.0. On an older
Node the worker throws at its first line. The caller then waits out the run's
timeout plus a second, and gets Fail(5). This happens for every Process.run in a
program run by that Node, whether as node p.cjs or in module mode. Bun is not
affected. Ubuntu 24.04 and Debian 12 package Node 18.19 as nodejs.

import Base

def show(r: Result<&1, &1, U32 & String, U32 & (String & String)>) -> String:
  match r:
    case Fail{(code, msg)}: "fail " ++ U32.show(code) ++ ": " ++ msg
    case Done{(code, (out, err))}: "done " ++ U32.show(code) ++ " " ++ out

def main() -> IO(Unit):
  do IO<Unit>:
    r : Result<&1, &1, U32 & String, U32 & (String & String)> <-
      Process.run("/bin/echo", ["hello"], "", 128, 1000)
    IO.print(show(r))
$ bun bend2/main.ts p.bend -o p.cjs && node p.cjs        # Node 18.19.1
fail 5: errno 5                                          # after about 2.1 s

The worker now uses getBuiltinModule when Node has it and require otherwise:

const load = process.getBuiltinModule ?? require;

Where getBuiltinModule exists, ?? never reads require, so a module-mode worker
on a current Node runs as before.

Results with this change, for node p.cjs, and for
node --input-type=module -e 'await import("./p.cjs")' and
node --input-type module -e '...':

main this PR
Node 18.19.1 fail 5: errno 5 (about 2.1 s) on all three done 0 hello (about 0.1 s) on all three
Node 24.22.3 done 0 hello done 0 hello
bun p.cjs done 0 hello done 0 hello

The new test tests/io/process_run_old_node builds that program and runs it with
node --require <preload>, where the preload does delete process.getBuiltinModule.
A --require preload also runs in worker threads, so this simulates an older Node on
any Node. It prints 1 on main and 0 with this change, under both Node 24.22.3 and
Node 18.19.1. Like process_run_node_module, it skips when no node is on PATH.

The five existing tests/io/process_run* tests on the JS lane and the interpreter:

With Node 24 on PATH, all 245 tests/io tests give the same results on main and with
this change, on the JS lane and on the interpreter. The C lane does not use this file.

Since bendlang#1842 the Process.run worker loads its modules with
process.getBuiltinModule, which Node added in v22.3.0 and v20.16.0. On an
older Node the worker throws at its first line, and Process.run answers
Fail(5) after its timeout plus a second. The worker now falls back to
require when getBuiltinModule is missing; on a current Node `??` never
reads require, so module-mode workers run as before.

process_run_old_node runs a Process.run program under Node with a preload
that deletes process.getBuiltinModule: 1 on main, 0 with this change.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@Lorenzobattistela Lorenzobattistela self-assigned this Nov 23, 2026
…n_node_module

process_run_old_node copied process_run_node_module's program, build and
checks; its preload (delete process.getBuiltinModule) is now a third run
there, returning 3 on failure. 0 with the fix, 3 with main's worker.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

@Lorenzobattistela Lorenzobattistela left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed on 07aa362 merged onto main 6b80619: repo 56/56, test 1868/1868, perf 124/124, ping 84/84, safe with 0 false rejects. No correctness findings.

I pushed b76461b: the old-Node case is now a third run inside process_run_node_module instead of a separate test that copied its program, build and checks (prints 0 with the fix, 3 with main's worker). Thanks for the fix.

@Lorenzobattistela
Lorenzobattistela merged commit d63eb65 into bendlang:main Nov 23, 2026
1 check passed
nicolas-abril added a commit to nicolas-abril/bend that referenced this pull request Nov 24, 2026
, bendlang#2224-bendlang#2226, bendlang#2231, bendlang#2285, bendlang#2286, bendlang#2288 and others)

One conflict, in emit_unfold: bendlang#2288 annotates an unfolded call's lets with
the argument types instantiated by the earlier arguments; bendlang#2162's deep unfold
keeps its arguments unannotated there and annotates them the same way after
folding (its type walk renamed D, beside bendlang#2288's T). Both kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants