Skip to content

Process.run ends the run on the Node host instead of running the program #1468

Closed

Description

@BaaRai

What you did

bend main.bend -o main.js, then node main.js, with main.bend the file below (a Process.run of /bin/echo). The standalone JS program is a verification lane recent fixes check on Node too (#1446, #1450), and AGENTS.md names the loader "for bun and node".

What happened

Under Bun the program prints the child's output and exits 0. Under Node the run ends before any answer:

$ bun main.js
Done 0 [hello
] []
end

$ node main.js
ReferenceError: Worker is not defined
        at process_run (...)
exit 1

A host without Bun has no global Worker and no Bun.spawn, so Process.run cannot run its worker and the ReferenceError ends the run through io_errs: the effect never answers, and every computation after it is lost. The same host abort hits the effects that bind libc through bun:ffi (File.read, File.read_bytes, File.read_at, TCP., UDP., Socket.close, Listener.close), which end with Error: Cannot find module 'bun:ffi'; those may be a design call (answer Fail on a host without FFI, or grow node paths), so I am keeping this issue on Process.run, which has a direct fix: node:child_process.spawnSync is the semantics the C lane models (#1392), and the fix PR runs on it.

Measured on current main (5e70819), Linux x86_64: the permanent tests/io/process_run.bend, emitted standalone and run under Node with the fix branch, answers all 19 rows True, including timeout (ETIMEDOUT), the combined output cap (EFBIG), a runaway descendant past the cap, exit and signal codes, and a missing executable (ENOENT).

The file

import Base

def show(r: Result<&1, &1, U32 & String, U32 & (String & String)>) -> String:
  match r:
    case Done{(code, (out, err))}:
      "Done " ++ U32.show(code) ++ " [" ++ out ++ "] [" ++ err ++ "]"
    case Fail{(c, m)}:
      "Fail " ++ U32.show(c) ++ " " ++ m

def main() -> IO(Unit):
  do IO<Unit>:
    a : Result<&1, &1, U32 & String, U32 & (String & String)> <-
      Process.run("/bin/echo", ["hello"], "", 4096, 3000)
    x : Unit <- IO.print(show(a))
    IO.print("end")

bend --version

main at 5e70819 (after 2.0.36), run through bun 1.4.2 and node v22.14.0

uname -sm

Linux x86_64

clang --version (the first line)

Debian clang version 14.0.6 (unrelated: the C lane was not part of this repro)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions