Skip to content

fix(daemon): skip Bun virtual entry path in detached child spawn#112

Open
dedene wants to merge 1 commit intosteipete:mainfrom
dedene:fix/daemon-bun-compiled-argv
Open

fix(daemon): skip Bun virtual entry path in detached child spawn#112
dedene wants to merge 1 commit intosteipete:mainfrom
dedene:fix/daemon-bun-compiled-argv

Conversation

@dedene
Copy link

@dedene dedene commented Mar 16, 2026

Problem

mcporter daemon start fails with "Failed to start daemon before timeout expired" when running from a Bun compiled binary (Homebrew install). The --foreground mode works fine.

The daemon launcher uses process.argv[1] as the CLI entry script when spawning the detached child process. In Node.js this is the script path, but in Bun compiled binaries it's a virtual /$bunfs/root/... path that Bun auto-injects into every spawned child. Including it explicitly duplicates it in the child's argv:

// Child sees:
process.argv = ["bun", "/$bunfs/root/mcporter", "/$bunfs/root/mcporter", "daemon", "start", "--foreground"]
//                                               ^^^^^^^^^^^^^^^^^^^^^^^^ duplicate

process.argv.slice(2) then parses the duplicate path as the CLI command instead of daemon, so the child silently fails to start.

This also affects mcporter list and mcporter call for keep-alive servers, since the DaemonClient auto-launches the daemon in the background.

Fix

Detect the /$bunfs/ prefix in resolveCliEntry() and omit it from spawn args — Bun already injects it automatically in the child.

Testing

  • pnpm test — all 418 tests pass
  • Compiled binary: bun run scripts/build-bun.ts then daemon start/status/stop cycle works
  • Node.js: node dist/cli.js daemon start still works (no regression)

Fixes #78

In Bun compiled binaries, process.argv[1] is a virtual /$bunfs/...
path that Bun auto-injects into every spawned child process. The
daemon launcher was including this path explicitly in the spawn args,
causing it to appear twice in the child's argv. The child then parsed
the duplicate path as the CLI command instead of "daemon", silently
failing to start.

Detect the /$bunfs/ prefix and omit the entry from spawn args, letting
Bun handle it automatically.
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.

Failed to connect to Google DevTools MCPs

1 participant