Skip to content

panic: switch on corrupt value in string.zig during long-running session on Windows #27099

@jiaoshi888

Description

@jiaoshi888

Description

Bun crashes with panic(main thread): switch on corrupt value after a long-running session on Windows. The crash appears to be a memory management issue in string object handling during event loop cleanup.

Crash Report

Bun crash report URL: https://bun.report/1.3.10/e_21979c94mgkgEuhogD09gkQ4p4vbq705Vwws1U23wN284hUm5nlOiq4kOwkzjwDCYKERNEL32.DLLo35FCSntdll.dllipmTA0eNorLs8sSc5QyM9TSM4vKiotKFEoS8wpTQUAa8EI/A

Environment

  • Bun Version: 1.3.10-canary.63 (1979c945)
  • Platform: Windows x64 (baseline)
  • OS: Windows 10 (win10_ni)
  • CPU: sse42 avx avx2

Runtime Statistics at Crash

Metric Value
Elapsed time 1,186,847ms (~19.7 minutes)
User CPU time 38,625ms
Sys CPU time 3,968ms
RSS Memory 0.86 GB
Peak Memory 0.93 GB
Commit Memory 1.21 GB
Page Faults 935,139
Machine RAM 68.53 GB

Stack Trace (from crash report)

The failure chain:

  1. string.zig:885 — dereference operation (root cause)
  2. Strong.zig:58 — during deinitialization
  3. event_loop.zig:501 — event loop cleanup
  4. JavaScript VM binding layer — surface crash point

Features Enabled at Crash

Bun.stderr, Bun.stdin, Bun.stdout, abort_signal, fetch, http_client_proxy, jsc, spawn, standalone_executable, process_dlopen, yaml_parse

Builtins Loaded

bun:main, node:assert, node:async_hooks, node:buffer, node:child_process, node:constants, node:crypto, node:events, node:fs, node:fs/promises, node:http, node:https, node:module, node:net, node:os, node:path, node:path/posix, node:path/win32, node:perf_hooks, node:process, node:stream, node:timers/promises, node:tls, node:tty, node:url, node:util, node:zlib, node:worker_threads, undici, ws, node:http2

Steps to Reproduce

  1. Run a Bun-based application (Claude Code CLI) on Windows
  2. Keep it running for an extended period (15–20+ minutes)
  3. During this time, memory usage grows to ~0.86 GB RSS
  4. Crash occurs with panic(main thread): switch on corrupt value

Expected Behavior

Bun should handle long-running sessions without crashing due to internal string object corruption.

Actual Behavior

panic(main thread): switch on corrupt value
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

Additional Context

  • This appears to be reproducible under high memory usage (>0.8 GB RSS) after extended runtime
  • The crash is consistent with memory corruption in string handling during event loop lifecycle management
  • Application is Claude Code CLI (claude.exe) which is distributed as a Bun standalone executable

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