bun icon indicating copy to clipboard operation
bun copied to clipboard

Many segmentation faults running compiled executable

Open rckok opened this issue 5 months ago • 6 comments

How can we reproduce the crash?

When running the compiled executable for my Node server, I get a segmentation fault almost every time, and with different stack traces each time (see below). I have tried debugging the executable by running BUN_INSPECT=localhost:6499/${prefix} ./${executable}, with breakpoints on uncaught exceptions and assertion failures turned on, but to no avail. At some point, it will crash with a segmentation fault, with no clear indication of the root cause. Below are the various stack traces I have gotten over the course of the last set of crashes.

Relevant log output


Stack Trace (bun.report)

Crash no. 1 —————— Bun v1.2.15 (df01799) on macos aarch64 [_]

Segmentation fault at address 0x42D1E206C61

  • 1 unknown/js code
  • allocators.BSSMap.BSSMapType.getOrPut
  • allocators.BSSMap.BSSMapType.getOrPut
  • resolver.resolver.Resolver.dirInfoCached
  • resolver.resolver.Resolver.loadAsFileOrDirectory
  • resolver.resolver.Resolver.checkRelativePath
  • resolver.resolver.Resolver.resolveWithoutSymlinks
  • resolver.resolver.Resolver.resolveAndAutoInstall
  • resolver.resolver.Resolver.resolveWithFramework
  • transpiler.Transpiler._resolveEntryPoint

Features: tsconfig, tsconfig_paths, workers_spawned, workers_terminated, process_dlopen, Bun.stderr, Bun.stdout, fetch, http_server, https_server, jsc, spawn, standalone_executable

Sentry Issue: BUN-MDF

—————— Crash no. 2 —————— Bun v1.2.15 (df01799) on macos aarch64 [_]

Segmentation fault at address 0x00000000

  • 1 unknown/js code
  • bun.js.event_loop.EventLoop.tickConcurrentWithCount
  • bun.js.event_loop.EventLoop.tickConcurrentWithCount
  • bun.js.event_loop.EventLoop.tick
  • bun.js.jsc.OpaqueWrap__anon_30396__struct_235725.callback
  • JSC__VM__holdAPILock
  • cli.Command.start
  • cli.Cli.start
  • main

Features: tsconfig, tsconfig_paths, workers_spawned, workers_terminated, process_dlopen, Bun.stderr, Bun.stdout, fetch, http_server, https_server, jsc, spawn, standalone_executable

Sentry Issue: BUN-MDC

—————— Crash no. 3 —————— Bun v1.2.15 (df01799) on macos aarch64 [_]

Segmentation fault at address 0x304DF394A1C

  • 1 unknown/js code
  • allocators.BSSMap.BSSMapType.getOrPut
  • allocators.BSSMap.BSSMapType.getOrPut
  • resolver.resolver.Resolver.dirInfoCachedMaybeLog__anon_27971
  • transpiler.Transpiler.runEnvLoader
  • transpiler.Transpiler.configureDefines
  • Thread.PosixThreadImpl.spawn__anon_1251567.Instance.entryFn

Features: tsconfig, tsconfig_paths, workers_spawned, workers_terminated, process_dlopen, Bun.stderr, Bun.stdout, fetch, http_server, https_server, jsc, spawn, standalone_executable

Sentry Issue: BUN-MDH

—————— Crash no. 4 —————— Bun v1.2.15 (df01799) on macos aarch64 [_]

Segmentation fault at address 0x7E6000169991D60

  • 1 unknown/js code
  • mi_heap_collect_ex
  • mi_heap_collect_ex
  • _mi_thread_done
  • 3 unknown/js code
  • bun.exitThread
  • bun.js.web_worker.exitAndDeinit
  • bun.js.jsc.OpaqueWrap__anon_1251663__struct_1251823.callback

Features: tsconfig, tsconfig_paths, workers_spawned, workers_terminated, process_dlopen, Bun.stderr, Bun.stdout, fetch, http_server, https_server, jsc, spawn, standalone_executable

rckok avatar Jun 12 '25 08:06 rckok

@rckok, thank you for reporting this crash. The latest version of Bun is v1.2.16, but this crash was reported on Bun v1.2.15.

Are you able to reproduce this crash on the latest version of Bun?

bun upgrade

For Bun's internal tracking, this issue is BUN-MDK.

github-actions[bot] avatar Jun 12 '25 08:06 github-actions[bot]

Yes, after upgrading to Bun v1.2.16 I again got a segmentation fault on the first run of the (re)compiled executable. This is the stack trace:

Bun v1.2.16 ([`631e674`](<https://github.com/oven-sh/bun/tree/631e6748422529a9dd807f3b0e583764c99ca1e0>)) on macos aarch64 [_]

Segmentation fault at address 0x2E737365636F7270

- *1 unknown/js code*
- `_mi_malloc_generic`
- `_mi_malloc_generic`
- `multi_array_list.MultiArrayList`
- `env_loader.Map.cloneWithAllocator`
- `Thread.PosixThreadImpl.spawn__anon_1260070.Instance.entryFn`

Features: tsconfig, tsconfig\_paths, workers\_spawned, workers\_terminated, process\_dlopen, Bun.stderr, Bun.stdout, fetch, http\_server, https\_server, jsc, spawn, standalone\_executable

<!-- from bun.report: DfCuw-Yajft2KSfMjGC_ -->

<sub>Sentry Issue: <strong><a href="https://bun-p9.sentry.io/issues/6674641877/">BUN-MDM</a></strong></sub>

Note that I also got a trace trap message in my console: [1] 57545 trace trap BUN_INSPECT=localhost:6499/<my prefix> ./<my executable> but no break on any uncaught exceptions in the debugger.

rckok avatar Jun 12 '25 08:06 rckok

I have run a Windows version of the executable on Windows, with the same result. The bug report link does not work (502 bad gateway), but below is the information that was logged to the console:

Bun v1.2.16 (631e6748) Windows x64
Windows v
.win11_dt
CPU:
sse42 avx avx2
Args: "<redacted executable path>"
Features: Bun.stderr
(2) Bun.stdout(2) fetch http_server(2) https_server jsc standalone_executable workers_spawned(784) workers_terminated(780) process_dlopen
Builtins: "bun:main" "node:assert" "node:async_hooks" "node:buffer" "node:child_process" "node:crypto" "node:events" "node:fs" "node:fs/promises" "node:http"
"
node:https" "node:net" "node:os" "node:path" "node:process" "node:querystring" "node:readline" "
node:stream" "node:stream/promises" "node:timers" "node:tty" "node:url" "node:util" "node:zlib" "node:worker_threads" "ws" "node-fetch"
Elapsed: 66875ms | User: 575515ms | Sys: 43687ms
RSS:
1.86GB | Peak: 2.66GB | Commit: 3.94GB | Faults: 17906476
panic(thread 30288): Segmentation fault at address 0x20008
oh no: Bun has crashed. This indicates a bug in Bun, not your code.
To send a redacted crash report to Bun's team,
please file a GitHub issue using the link below:

https://bun.report/1.2.16/w_1631e674gLqgk8ggBuu4/FivzNi78O2rjPq40PwshqdCYKERNEL32.DLLut0LCSntdll.dll40hPA2AwggI

rckok avatar Jun 12 '25 08:06 rckok

can you run bun run env and paste the output (and mask any values which are sensitive, such as API keys)

Jarred-Sumner avatar Jun 12 '25 08:06 Jarred-Sumner

Of course, here it is:

MallocNanoZone=0
USER=ralph.kok
COMMAND_MODE=unix2003
__CFBundleIdentifier=com.todesktop.230313mzl4w4u92
PATH=/Users/ralph.kok/Projects/<project path>:/Users/ralph.kok/Projects/<project path>/dist/node_modules/.bin:/Users/ralph.kok/Projects/<project path>/dist/node_modules/.bin:/Users/ralph.kok/Projects/<project path>/node_modules/.bin:/Users/ralph.kok/Projects/<project parent dir path>/node_modules/.bin:/Users/ralph.kok/Projects/node_modules/.bin:/Users/ralph.kok/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/ralph.kok/.bun/bin:/Users/ralph.kok/.rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/ralph.kok/.pyenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/Homebrew/bin:/Users/ralph.kok/anaconda2/bin:/usr/local/bin/php:/Users/ralph.kok/.bun/bin:/Users/ralph.kok/.rbenv/shims:/Users/ralph.kok/.cargo/bin:/usr/local/bin/node:/Users/ralph.kok/Projects/pico/picotool/build:/Applications/ruffle_nightly_2020_11_20_mac:/usr/local/opt/rabbitmq/sbin:/Users/ralph.kok/.cursor/extensions/ms-python.debugpy-2025.8.0-darwin-arm64/bundled/scripts/noConfigScripts
LOGNAME=ralph.kok
DISPLAY=/private/tmp/com.apple.launchd.aRgQiacT7n/org.xquartz:0
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BArzLBLoEX/Listeners
HOME=/Users/ralph.kok
SHELL=/bin/zsh
TMPDIR=/var/folders/r1/r8jt4s617g5g_s3_ylz915t40000gn/T/
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
XPC_SERVICE_NAME=0
XPC_FLAGS=0x0
ORIGINAL_XDG_CURRENT_DESKTOP=undefined
CURSOR_TRACE_ID=75a397e035db4f3c91b37e78536746bf
SHLVL=1
PWD=/<project path>/dist
OLDPWD=/<project path>
P4IGNORE=p4ignore.txt
PICO_SDK_PATH=/Users/ralph.kok/Projects/pico/pico-sdk
QT_DIR=/Users/ralph.kok/Qt/5.11.3/clang_64/
OPENSSL_ROOT_DIR=/usr/local/Cellar/[email protected]/1.1.1d
HOMEBREW_PREFIX=/opt/homebrew
HOMEBREW_CELLAR=/opt/homebrew/Cellar
HOMEBREW_REPOSITORY=/opt/homebrew
INFOPATH=/opt/homebrew/share/info:/opt/homebrew/share/info:
PYENV_SHELL=zsh
GENICAM_GENTL64_PATH=/usr/local/lib/flir-gentl:/usr/local/lib/flir-gentl
RBENV_SHELL=zsh
ZSH=/Users/ralph.kok/.oh-my-zsh
PAGER=less
LESS=-R
LSCOLORS=Gxfxcxdxbxegedabagacad
LS_COLORS=di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43
MISE_SHELL=zsh
__MISE_ORIG_PATH=/Users/ralph.kok/.rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/ralph.kok/.pyenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/Homebrew/bin:/Users/ralph.kok/anaconda2/bin:/usr/local/bin/php:/Users/ralph.kok/.bun/bin:/Users/ralph.kok/.rbenv/shims:/Users/ralph.kok/.cargo/bin:/usr/local/bin/node:/Users/ralph.kok/Projects/pico/picotool/build:/Applications/ruffle_nightly_2020_11_20_mac:/usr/local/opt/rabbitmq/sbin:/Users/ralph.kok/.cursor/extensions/ms-python.debugpy-2025.8.0-darwin-arm64/bundled/scripts/noConfigScripts
__MISE_DIFF=eAFrXpyfk9KwOC+1vGFJQWJJxgQASssINA
__MISE_SESSION=eAFrX5OTn5iSmhJfkp+fUzxhHZSXnJ+XlplePGENhBFfkFiSUTxhcWpeWcPilMyim8b6ocWpRcX6RYk5BRl62fnZ+gFF+VmpySXF+u45icXFzvmlRSX67s7+wfHO+UWp+imZxSVrUvPK4ssSi+IzEoszNqQlmxkYmCYbJSebm6UZmxuuzUksSS0uiS8tSEksST0iwAAHjNPjLqvxAwAlQj+h
BUN_INSTALL=/Users/ralph.kok/.bun
TERM_PROGRAM=vscode
TERM_PROGRAM_VERSION=1.0.0
LANG=en_US.UTF-8
COLORTERM=truecolor
VSCODE_ENV_PREPEND=PS1=(3.9.0) 
GIT_ASKPASS=/Applications/Cursor.app/Contents/Resources/app/extensions/git/dist/askpass.sh
VSCODE_GIT_ASKPASS_NODE=/Applications/Cursor.app/Contents/Frameworks/Cursor Helper (Plugin).app/Contents/MacOS/Cursor Helper (Plugin)
VSCODE_GIT_ASKPASS_EXTRA_ARGS=
VSCODE_GIT_ASKPASS_MAIN=/Applications/Cursor.app/Contents/Resources/app/extensions/git/dist/askpass-main.js
VSCODE_GIT_IPC_HANDLE=/var/folders/r1/r8jt4s617g5g_s3_ylz915t40000gn/T/vscode-git-dc2cebb0b9.sock
PYDEVD_DISABLE_FILE_VALIDATION=1
VSCODE_DEBUGPY_ADAPTER_ENDPOINTS=/Users/ralph.kok/.cursor/extensions/ms-python.debugpy-2025.8.0-darwin-arm64/.noConfigDebugAdapterEndpoints/endpoint-47b8bf5fa91ff4fa.txt
BUNDLED_DEBUGPY_PATH=/Users/ralph.kok/.cursor/extensions/ms-python.debugpy-2025.8.0-darwin-arm64/bundled/libs/debugpy
TERM=xterm-256color
_=/Users/ralph.kok/.bun/bin/bun
npm_config_local_prefix=/Users/ralph.kok/Projects/<project path>/dist
npm_config_user_agent=bun/1.2.14 npm/? node/v22.6.0 darwin arm64
npm_execpath=/Users/ralph.kok/.bun/bin/bun
npm_package_name=<project executable name>
npm_package_json=/Users/ralph.kok/Projects/<project path>/package.json
npm_package_version=5.0.1
NODE=/usr/local/bin/node
npm_node_execpath=/usr/local/bin/node
npm_command=run-script

rckok avatar Jun 12 '25 08:06 rckok

I have found an issue in my code that may be instrumental in leading to this situation. Please hold off on investigating too deeply until I can confirm whether this is the case or not.

rckok avatar Jun 13 '25 06:06 rckok

It looks like these segmentation faults may be the indirect result of an issue running workers. It seems that I cannot get the executable to find the workers' files whatever I try, resulting in an endless iteration of workers exiting and being respawned. Let's close this issue for now, as I'm quite sure that this must be at the root of the crashes I'm experiencing.

rckok avatar Jun 16 '25 11:06 rckok