Repository navigation
Conversation
…a compiled executable Inside a bun build --compile binary, child_process.fork(modulePath) spawns process.execPath (the compiled binary itself), which unconditionally booted the embedded main entry point and treated modulePath as a passthrough arg. The forked module never ran, and unguarded forks self-respawned. fork() now sets BUN_INTERNAL_FORK_ENTRY when spawning itself from a standalone executable. boot_standalone reads it, resolves it against the embedded module graph (with the same extension remapping new Worker(path) uses) and uses that as the entry point, falling back to disk for non-embedded paths. argv after the module path becomes process.argv[2..] as fork() callers expect. cluster.fork() goes through the same path.
|
Reproduced: PR: #35129 Tests: CI: the only hard failures are |
|
Warning Review limit reached
Next review available in: 8 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
Comment |
|
Updated 10:38 AM PT - Jul 22nd, 2026
❌ @robobun, your commit e249586 has 3 failures in
🧪 To try this PR locally: bunx bun-pr 35129That installs a local version of the PR into your bun-35129 --bun |
…rk env var from process.env The extension-remapping probe now lives as a provided method on the resolver's StandaloneModuleGraph trait so new Worker(path) and child_process.fork(path) inside a compiled binary use the same table. BUN_INTERNAL_FORK_ENTRY is removed from the env loader map alongside NODE_CHANNEL_FD so it never shows up in process.env. std::env::remove_var alone does not touch the WTF-8 snapshot on Windows. The compile/ChildProcessForkEmbedded test now reads stdout and the IPC message from state inside the 'close' handler so the assertion does not depend on message vs exit ordering.
…ONS tokens append_options_env inserts those tokens at argv[1], so a spliced flag value that happens to equal the fork module path would match first and shift the child's process.argv. offset_for_passthrough is already the first OS-passed arg slot.
The merged env object in fork() now starts with __proto__: null like the
other option merges in this file.
resolve_entry_point_specifier keeps its original ./ and ../ gate around
the embedded-graph probe so new Worker('bare.ts') still falls through to
the resolver; only the extension table is shared.
…s the module-path slot directly The value is now '<execArgv.length>:<modulePath>'. boot_standalone strips the prefix and takes offset_for_passthrough + execArgv_len as the module-path argv index, so there is no byte-equality scan left to collide with an execArgv token or a user arg that happens to equal the module path.
There was a problem hiding this comment.
All prior review feedback has been addressed and no new issues were found on e249586. Deferring to a human for the design sign-off: this introduces a new internal env-var protocol (BUN_INTERNAL_FORK_ENTRY=<execArgvLen>:<modulePath>) and rewires the boot_standalone entry-point selection, which is worth a maintainer's eyes.
What was reviewed:
- The
<count>:<path>encoding andoffset_for_passthrough + exec_argv_lenindex math — traced through both thecompile_exec_argv/BUN_OPTIONSsplice branch and the no-splice branch; the value-scan is gone and.min(argv.len())prevents overshoot. resolve_embedded_entryvs. the removedweb_worker.rsblock — the.//../gate is restored at the Worker call site sonew Worker(bare)semantics are unchanged; the extension probe matches the old table byte-for-byte.- Env-var hygiene — scrubbed from the env-loader map in
VirtualMachine.rs(covers the Windows WTF-8 snapshot) andremove_varfor POSIX libc environ; the test assertsleaked=false. - Test now waits on
'close'and captures the IPC message into a variable, so the earlier ordering concern is resolved.
Extended reasoning...
Overview
This PR makes child_process.fork(modulePath) (and by extension cluster.fork()) work inside a bun build --compile binary. It touches seven files: a new BUN_INTERNAL_FORK_ENTRY env-var declaration in bun_core/env_var.rs; the fork() implementation in src/js/node/child_process.ts (sets the env var when spawning self); src/runtime/cli/mod.rs (boot_standalone reads/consumes the env var and picks the entry module + passthrough slice); src/jsc/VirtualMachine.rs (scrubs the var from process.env); a new shared resolve_embedded_entry default method on the StandaloneModuleGraph trait in src/resolver/; src/jsc/web_worker.rs refactored to call it; and two new itBundled tests in bundler_compile.test.ts.
Security risks
Low. The env var is internal, only honoured when the process is already a standalone executable, and only selects among modules already embedded in the binary (or resolves against cwd, which is what plain bun <file> does anyway). The __proto__: null on the merged env object was added per earlier review. No new external input surface.
Level of scrutiny
High. boot_standalone is the entry point for every compiled executable, and the change introduces a small internal protocol between parent and child processes. The Worker resolution refactor moves ~60 lines of load-bearing extension-remapping logic into a shared trait method. Over four review iterations the implementation has converged (Windows env snapshot, argv-index computation replacing a value scan, null-proto env merge, preserving the Worker ./ guard), and the current diff looks correct to me — but the design choice of env-var signaling (vs. e.g. an argv sentinel or a reserved flag) and the interaction with compile_exec_argv/BUN_OPTIONS splicing are the kind of thing a maintainer should ratify.
Other factors
All four of my prior inline threads are resolved by the author with targeted follow-up commits, and the multi-agent bug hunter found nothing on the latest revision. CI failures noted in the thread are pre-existing GC-timing tests also red on main. Two new tests cover both fork() and cluster.fork() and assert argv shape, IPC round-trip, and that the internal env var does not leak into process.env. Given the breadth (CLI boot path + Node-compat JS + resolver trait + Worker refactor) and that this is a new user-facing capability, I'm deferring rather than approving.
|
Closing as part of a cleanup of stale pull requests. This PR has had no new commits since 2026-07-22, it conflicts with main, and its last CI run failed. This is not a judgment on the fix itself. If the problem still reproduces on a current build, reopen this PR after a rebase or open a new one against main. |
Problem
Inside a
bun build --compilebinary,child_process.fork(\"./job.mjs\")spawnsprocess.execPath(the compiled binary itself). A standalone executable always booted its embedded main entry point, so./job.mjswas demoted toprocess.argv[2]and the forked module never ran. Unguarded, the child re-executed the parent program, which forked again: an exponential self-respawn storm.cluster.fork()hit the same path and leaked the module path into the worker'sprocess.argv.Repro
Before:
PARENT: child exit=7 out=\"SPAWNED-AS-MAIN depth=1 argv=[\\\"bun\\\",\\\"/\$bunfs/root/app\\\",\\\"./job.mjs\\\",\\\"a1\\\"]\"After:
PARENT: child exit=0 out=\"job.mjs RAN args=[\\\"a1\\\"]\"Cause
boot_standaloneinsrc/runtime/cli/mod.rshard-codesgraph.entry_point()as the module to run and puts all ofargv[1..]intoctx.passthrough. There was no mechanism for a compiled binary to be told "run this other embedded module instead".new Worker(path)already had graph-aware resolution, butfork()spawns a fresh process so that path never applied.Fix
When
fork()runs inside a standalone executable and is spawning itself, it setsBUN_INTERNAL_FORK_ENTRY=<modulePath>in the child's environment. The child'sboot_standalonereads and unsets it, resolves it against the embedded module graph using the same extension remappingnew Worker(path)uses (./job.mjs->/\$bunfs/root/job.js), and boots that module instead of the baked entry point. Everything in argv after the module path becomesprocess.argv[2..]. If the module is not embedded, the path is resolved against cwd so on-disk scripts still work; a missing module surfaces as a normal "Module not found" error.cluster.fork()goes through the samechild_process.fork(), so cluster workers now boot with a cleanprocess.argvtoo.Verification
Both new tests fail on the released binary (
MAIN-REENTERED argv=[\"./job.mjs\",\"hello\"]/argv=[\"/\$bunfs/root/out\"]) and pass with this change.compile-argv.test.ts, the existingcompile/Worker*tests,test/js/node/cluster.test.ts, and the Node-portedtest-child-process-fork-*suite continue to pass.no test proof · iteration 3 · Platform-specific test(s) that do not run on this machine. Deferring to CI, which covers all platforms: test/bundler/bundler_compile.test.ts