Skip to content

Windows standalone executable crashes spawning Worker when autoloadDotenv=false and .env exists #27431

Closed

Description

@Hona

What version of Bun is running?

1.3.10-canary.104+32a89c433

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

Repro repo: https://github.com/Hona/bun1310-minimal-repro

Run this in a directory containing a .env file:

bun repro-short.ts

The script is:

await Bun.write("r.ts", 'new Worker("data:text/javascript,")\n');
await Bun.build({
  entrypoints: ["./r.ts"],
  compile: {
    autoloadDotenv: false,
    target: "bun-windows-x64",
    outfile: "./r.exe",
  },
});
Bun.spawnSync(["./r.exe"], {
  stdin: "inherit",
  stdout: "inherit",
  stderr: "inherit",
});

This reduces to:

  • build a standalone executable
  • set compile.autoloadDotenv = false
  • run the executable in a cwd that contains .env
  • have the executable do new Worker(...)

On my machine, removing any one of those stops reproducing.

What is the expected behavior?

The standalone executable should exit cleanly. The presence of a .env file in cwd should not matter when autoloadDotenv is disabled.

What do you see instead?

The compiled executable panics immediately:

panic(thread ...): Internal assertion failure: `ThreadLock` is locked by thread ..., not thread ...
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

One sample crash from this repro:

============================================================
Bun Canary v1.3.10-canary.104 (32a89c43) Windows x64
Windows v.win11_ge
CPU: sse42 avx avx2
Args: "./r.exe"
Features: jsc standalone_executable workers_spawned
Builtins: "bun:main"
Elapsed: 51ms | User: 15ms | Sys: 15ms
RSS: 0.14GB | Peak: 0.14GB | Commit: 0.39GB | Faults: 34252 | Machine: 34.03GB

panic(thread 48292): Internal assertion failure: `ThreadLock` is locked by thread 58860, not thread 48292
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

Additional information

Confirmed non-factors in this repro:

  • extra exec flags are not required
  • custom worker files are not required
  • worker contents are not required
  • explicit env passing is not required
  • process.chdir() is not required

Confirmed sanity checks:

  • removing .env avoids the crash
  • leaving autoloadDotenv at its default avoids the crash
  • removing the Worker avoids the crash

Activity

  1. github-actions commented on Feb 25, 2026

    @github-actions
    Contributor

    Found 3 possible duplicate issues:

    1. Deadlock: all threads permanently blocked due to lock ordering violation between allocator and thread pool (macOS arm64, Bun 1.3.5 SEA) #26762
    2. Crash in bmalloc (pas_assertion_failed) on Windows x64 baseline in standalone executable #26982
    3. MessageChannel between Workers causes crash/unexpected exit #25805

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. added a commit that references this issue on Feb 25, 2026
    64f4e76
  3. added a commit that references this issue on Feb 26, 2026
    84e4a5c
  4. added a commit that references this issue on Apr 25, 2026
    83c95ee
  5. added a commit that references this issue on May 14, 2026
    daed6c0
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