Repository navigation
Closed
Description
How can we reproduce the crash?
I added newrelic to the project, added import 'newrelic'; to my test file and ran the following (in fish);
env NEW_RELIC_APP_NAME=myprojg NEW_RELIC_LICENSE_KEY=redacted bun test myfile.test.ts
Also tested in bash (without env first) with same result
Got this in console:
bun test v1.2.21 (7c45ed97)
myfile.test.ts:
============================================================
Bun v1.2.21 (7c45ed97) macOS Silicon
macOS v15.6.1
CPU: fp aes crc32 atomics
Args: "bun" "test" "myfile.test.ts"
Features: Bun.stderr(2) Bun.stdout(2) bunfig dotenv jsc transpiler_cache(4) tsconfig(3) tsconfig_paths
Builtins: "node:assert" "node:async_hooks" "node:buffer" "node:child_process" "node:crypto" "node:dns" "node:events" "node:fs" "node:fs/promises" "node:http" "node:https" "node:module" "node:net" "node:os" "node:path" "node:stream" "node:timers" "node:tls" "node:tty" "node:url" "node:util" "node:zlib" "node:worker_threads" "node:inspector" "node:diagnostics_channel"
Elapsed: 160ms | User: 155ms | Sys: 54ms
RSS: 103.25MB | Peak: 103.25MB | Commit: 1.07GB | Faults: 86 | Machine: 34.36GB
panic(main thread): Segmentation fault at address 0x0
Crashed while loading native module: /Users/pal/dev/redacted/node_modules/.bun/@newrelic+native-metrics@12.0.0/node_modules/@newrelic/native-metrics/prebuilds/darwin-arm64/@newrelic+native-metrics.abi137.uv1.armv8.glibc.node
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.21/Mt17c45ed94Bq0gQ___u22unB______A2AA
fish: Job 1, 'env NEW_RELIC_APP_NAME=redacted…' terminated by signal SIGTRAP (Trace or breakpoint trap)
Relevant log output
Stack Trace (bun.report)
Bun v1.2.21 (7c45ed9) on macos aarch64 [RunCommand]
Segmentation fault at address 0x00000000
- 3 unknown/js code
node.cpp:95:node_module_register
Features: tsconfig, Bun.stderr, dotenv, jsc
Sentry Issue: BUN-DCM
Reacted by Gerard de Brieder and Joaquin Bravo Contreras
Activity
linear commentedon Sep 13, 2025
ENG-20416 Tried to use newrelic with Bun
robobun commentedon Mar 18, 2026
This was fixed in #24403.
Issue Summary
Segfault (at address 0x0) when loading
@newrelic/native-metricsnative.nodemodule viaprocess.dlopen. The crash occurred innode_module_registeratsrc/bun.js/bindings/v8/node.cpp:95(old line numbering).Root Cause
In the original code,
strongExportsObjectwas conditionally initialized: ifmodule.exportswas null, undefined, or a primitive value, theif (exportsObject && exportsObject.isObject())guard would skip initialization. Later at line 97 (now line 97),*strongExportsObjectwas dereferenced unconditionally, causing a null pointer dereference (segfault at address 0x0).Fix Applied
Two commits fixed this and related issues:
c7b9e0dc92(PR fix(node): prevent crash with null/undefined exports in process.dlopen #24403): "fix(node): prevent crash with null/undefined exports in process.dlopen"getIfPropertyExists()toget()toObject()to guaranteestrongExportsObjectis always initialized2dd997c4b5(PR fix(node): support duplicate dlopen calls with DLHandleMap #24404): "fix(node): support duplicate dlopen calls with DLHandleMap"Current Code (Fixed)
In
src/bun.js/bindings/v8/node.cpplines 78-89:The
toObject()call guarantees that either:exportsis a valid JSObject pointer (andstrongExportsObjectgets initialized), ORRETURN_IF_EXCEPTIONThis prevents the null pointer dereference at line 97 where
*strongExportsObjectis used.Test Coverage
Tests were added to verify the fixes:
test/js/node/process/dlopen-non-object-exports.test.ts- Tests null/undefined/primitive exportstest/js/node/process/dlopen-duplicate-load.test.ts- Tests duplicate module loadingThis is an automated comment.