Repository navigation
Get bun ready for linux builds - #26
Merged
Merged
Conversation
Adds: conditional builds in makefile Fixes: incorrect imports of 'JavaScriptCore.zig' (note the caps 's') replaces with correct import of 'JavascriptCore.zig'
Jarred-Sumner
approved these changes
Sep 17, 2021
DAlperin
commented
Sep 17, 2021
| @@ -134,9 +142,10 @@ jsc-build-mac-compile: | |||
| jsc-build-linux-compile: | |||
Contributor
Author
There was a problem hiding this comment.
Oops forgot to fix the missing " I'll do that in the next patchset
Jarred-Sumner
pushed a commit
that referenced
this pull request
Aug 8, 2025
<details> <summary> observed in https://buildkite.com/bun/bun/builds/22442#annotation-test/js/node/zlib/leak.test.ts </summary> ``` ==5045==ERROR: AddressSanitizer: heap-use-after-free on address 0x5220000243c0 at pc 0x00000dad671b bp 0x14f22d4a4990 sp 0x14f22d4a4988 READ of size 8 at 0x5220000243c0 thread T5 (HeapHelper) ======== Stack trace from GDB for HeapHelper-5045.core: ======== Program terminated with signal SIGABRT, Aborted. #0 0x000014f2c3672eec in ?? () from /lib/x86_64-linux-gnu/libc.so.6 [Current thread is 1 (Thread 0x14f22d4f46c0 (LWP 5050))] #0 0x000014f2c3672eec in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x000014f2c3623fb2 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x000014f2c360e472 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #3 0x000000000e3b2ae2 in uw_init_context_1[cold] () #4 0x000000000e3b29fc in _Unwind_Backtrace () #5 0x00000000046a6bab in __sanitizer::BufferedStackTrace::UnwindSlow(unsigned long, unsigned int) () #6 0x00000000046a181d in __sanitizer::BufferedStackTrace::Unwind(unsigned int, unsigned long, unsigned long, void*, unsigned long, unsigned long, bool) () #7 0x00000000046885bd in __sanitizer::BufferedStackTrace::UnwindImpl(unsigned long, unsigned long, void*, bool, unsigned int) () #8 0x0000000004601127 in __asan::ErrorGeneric::Print() () #9 0x0000000004683180 in __asan::ScopedInErrorReport::~ScopedInErrorReport() () #10 0x0000000004686567 in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) () #11 0x0000000004686d46 in __asan_report_load8 () #12 0x000000000dad671b in ZSTD_sizeof_CCtx (cctx=<optimized out>) at ./build/release-asan/zstd/vendor/zstd/lib/compress/zstd_compress.c:210 #13 0x0000000006d2284d in bun.js.node.zlib.NativeZstd.estimatedSize () at /var/lib/buildkite-agent/builds/ip-172-31-72-121/bun/bun/src/bun.js/node/zlib/NativeZstd.zig:57 #14 ZigGeneratedClasses.JSNativeZstd.JavaScriptCoreBindings.NativeZstd__estimatedSize (thisValue=<optimized out>) at /var/lib/buildkite-agent/builds/ip-172-31-72-121/bun/bun/build/release-asan/codegen/ZigGeneratedClasses.zig:11122 #15 0x000000000852803b in WebCore::JSNativeZstd::visitChildrenImpl<JSC::SlotVisitor> (cell=0x14f22e190840, visitor=...) at ./build/release-asan/./build/release-asan/codegen/ZigGeneratedClasses.cpp:30728 #16 WebCore::JSNativeZstd::visitChildren (cell=0x14f22e190840, visitor=...) at ./build/release-asan/./build/release-asan/codegen/ZigGeneratedClasses.cpp:30734 #17 0x000000000aa99d6c in JSC::MethodTable::visitChildren (this=<optimized out>, cell=<optimized out>, visitor=...) at vendor/WebKit/Source/JavaScriptCore/runtime/ClassInfo.h:115 #18 0x000000000aa99d6c in JSC::SlotVisitor::visitChildren (this=0x14f277028300, cell=0x14f22e190840) #19 JSC::SlotVisitor::drain(WTF::MonotonicTime)::$_0::operator()(JSC::MarkStackArray&) const (this=<optimized out>, stack=...) at vendor/WebKit/Source/JavaScriptCore/heap/SlotVisitor.cpp:509 #20 0x000000000aa8f130 in JSC::SlotVisitor::forEachMarkStack<JSC::SlotVisitor::drain(WTF::MonotonicTime)::$_0>(JSC::SlotVisitor::drain(WTF::MonotonicTime)::$_0 const&) (this=0x14f277028300, func=...) at vendor/WebKit/Source/JavaScriptCore/heap/SlotVisitorInlines.h:193 #21 JSC::SlotVisitor::drain (this=this@entry=0x14f277028300, timeout=<error reading variable: That operation is not available on integers of more than 8 bytes.>, timeout@entry=...) at vendor/WebKit/Source/JavaScriptCore/heap/SlotVisitor.cpp:499 #22 0x000000000aa90590 in JSC::SlotVisitor::drainFromShared (this=0x14f277028300, sharedDrainMode=JSC::SlotVisitor::HelperDrain, timeout=<error reading variable: That operation is not available on integers of more than 8 bytes.>) at vendor/WebKit/Source/JavaScriptCore/heap/SlotVisitor.cpp:699 #23 0x000000000aa08726 in JSC::Heap::runBeginPhase(JSC::GCConductor)::$_1::operator()() const (this=<optimized out>) at vendor/WebKit/Source/JavaScriptCore/heap/Heap.cpp:1508 #24 WTF::SharedTaskFunctor<void (), JSC::Heap::runBeginPhase(JSC::GCConductor)::$_1>::run() (this=<optimized out>) at .WTF/Headers/wtf/SharedTask.h:91 #25 0x000000000aa3b596 in WTF::ParallelHelperClient::runTask(WTF::RefPtr<WTF::SharedTask<void ()>, WTF::RawPtrTraits<WTF::SharedTask<void ()> >, WTF::DefaultRefDerefTraits<WTF::SharedTask<void ()> > > const&) (this=0x14f22e000428, task=...) at vendor/WebKit/Source/WTF/wtf/ParallelHelperPool.cpp:110 #26 0x000000000aa3d976 in WTF::ParallelHelperPool::Thread::work (this=<optimized out>) at vendor/WebKit/Source/WTF/wtf/ParallelHelperPool.cpp:201 #27 0x000000000aa4210d in WTF::AutomaticThread::start(WTF::AbstractLocker const&)::$_0::operator()() const (this=<optimized out>) at vendor/WebKit/Source/WTF/wtf/AutomaticThread.cpp:225 #28 WTF::Detail::CallableWrapper<WTF::AutomaticThread::start(WTF::AbstractLocker const&)::$_0, void>::call() (this=<optimized out>) at vendor/WebKit/Source/WTF/wtf/Function.h:53 #29 0x0000000008958ada in WTF::Function<void ()>::operator()() const (this=<optimized out>) at vendor/WebKit/Source/WTF/wtf/Function.h:82 #30 WTF::Thread::entryPoint (newThreadContext=<optimized out>) at vendor/WebKit/Source/WTF/wtf/Threading.cpp:272 #31 0x0000000008a65689 in WTF::wtfThreadEntryPoint (context=0x13b5) at vendor/WebKit/Source/WTF/wtf/posix/ThreadingPOSIX.cpp:255 #32 0x000000000467d347 in asan_thread_start(void*) () #33 0x000014f2c36711f5 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #34 0x000014f2c36f189c in ?? () from /lib/x86_64-linux-gnu/libc.so.6 ``` </details> `ZSTD_sizeof_CCtx` and `ZSTD_sizeof_DCtx` can not be relied upon to be thread-safe and estimatedSize may be called from any thread
Jarred-Sumner
added a commit
that referenced
this pull request
Aug 20, 2025
…Worker" (#21994) Reverts #21962 `vm.ensureTerminationException` allocates a JSString, which is not safe to do from a thread that doesn't own the API lock. ```ts Bun Canary v1.2.21-canary.1 (f706382a) Linux x64 (baseline) Linux Kernel v6.12.38 | musl CPU: sse42 popcnt avx avx2 avx512 Args: "/var/lib/buildkite-agent/builds/ip-172-31-38-185/bun/bun/release/bun-linux-x64-musl-baseline-profile/bun-profile" "/var/lib/buildkite-agent/builds/ip-172-31-38-185/bun/bun/test/js/node/worker_threads"... Features: bunfig http_server jsc tsconfig(3) tsconfig_paths workers_spawned(40) workers_terminated(34) Builtins: "bun:main" "node:worker_threads" Elapsed: 362ms | User: 518ms | Sys: 63ms RSS: 0.34GB | Peak: 100.36MB | Commit: 0.34GB | Faults: 0 | Machine: 8.17GB panic(main thread): Segmentation fault at address 0x0 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: http://localhost:38809/1.2.21/Ba2f706382wNgkgUu11luEm6yX+lwy+Dgtt+oEurthoD8214mE___07+09DA2AA 6 | describe("Worker destruction", () => { 7 | const method = ["Bun.connect", "Bun.listen", "fetch"]; 8 | describe.each(method)("bun when %s is used in a Worker that is terminating", method => { 9 | // fetch: ASAN failure 10 | test.skipIf(isBroken && method == "fetch")("exits cleanly", () => { 11 | expect([join(import.meta.dir, "worker_thread_check.ts"), method]).toRun(); ^ error: Command /var/lib/buildkite-agent/builds/ip-172-31-38-185/bun/bun/test/js/node/worker_threads/worker_thread_check.ts Bun.connect failed: Spawned 10 workers RSS 79 MB Spawned 10 workers RSS 87 MB Spawned 10 workers RSS 90 MB at <anonymous> (/var/lib/buildkite-agent/builds/ip-172-31-38-185/bun/bun/test/js/node/worker_threads/worker_destruction.test.ts:11:73) ✗ Worker destruction > bun when Bun.connect is used in a Worker that is terminating > exits cleanly [597.56ms] ✓ Worker destruction > bun when Bun.listen is used in a Worker that is terminating > exits cleanly [503.47ms] » Worker destruction > bun when fetch is used in a Worker that is terminating > exits cleanly 1 pass 1 skip 1 fail 2 expect() calls Ran 3 tests across 1 file. [1125.00ms] ======== Stack trace from GDB for bun-profile-28234.core: ======== Program terminated with signal SIGILL, Illegal instruction. #0 crash_handler.crash () at crash_handler.zig:1523 [Current thread is 1 (LWP 28234)] #0 crash_handler.crash () at crash_handler.zig:1523 #1 0x0000000002db77aa in crash_handler.crashHandler (reason=..., error_return_trace=0x0, begin_addr=...) at crash_handler.zig:471 #2 0x0000000002db2b55 in crash_handler.handleSegfaultPosix (sig=<optimized out>, info=<optimized out>) at crash_handler.zig:792 #3 0x0000000004716b58 in WTF::jscSignalHandler (sig=11, info=0x7ffe54051e90, ucontext=0x0) at vendor/WebKit/Source/WTF/wtf/threads/Signals.cpp:548 #4 <signal handler called> #5 JSC::VM::currentThreadIsHoldingAPILock (this=0x148296c30000) at vendor/WebKit/Source/JavaScriptCore/runtime/VM.h:840 #6 JSC::sanitizeStackForVM (vm=...) at vendor/WebKit/Source/JavaScriptCore/runtime/VM.cpp:1369 #7 0x0000000003f4a060 in JSC::LocalAllocator::allocate(JSC::Heap&, unsigned long, JSC::GCDeferralContext*, JSC::AllocationFailureMode)::{lambda()#1}::operator()() const (this=<optimized out>) at cache/webkit-a73e665a39b281c5/include/JavaScriptCore/LocalAllocatorInlines.h:46 #8 JSC::FreeList::allocateWithCellSize<JSC::LocalAllocator::allocate(JSC::Heap&, unsigned long, JSC::GCDeferralContext*, JSC::AllocationFailureMode)::{lambda()#1}>(JSC::LocalAllocator::allocate(JSC::Heap&, unsigned long, JSC::GCDeferralContext*, JSC::AllocationFailureMode)::{lambda()#1} const&, unsigned long) (this=0x148296c38e48, cellSize=16, slowPath=...) at cache/webkit-a73e665a39b281c5/include/JavaScriptCore/FreeListInlines.h:46 #9 JSC::LocalAllocator::allocate (this=0x148296c38e30, heap=..., cellSize=16, deferralContext=0x0, failureMode=JSC::AllocationFailureMode::Assert) at cache/webkit-a73e665a39b281c5/include/JavaScriptCore/LocalAllocatorInlines.h:44 #10 JSC::GCClient::IsoSubspace::allocate (this=0x148296c38e30, vm=..., cellSize=16, deferralContext=0x0, failureMode=JSC::AllocationFailureMode::Assert) at cache/webkit-a73e665a39b281c5/include/JavaScriptCore/IsoSubspaceInlines.h:34 #11 JSC::tryAllocateCellHelper<JSC::JSString, (JSC::AllocationFailureMode)0> (vm=..., size=16, deferralContext=0x0) at cache/webkit-a73e665a39b281c5/include/JavaScriptCore/JSCellInlines.h:192 #12 JSC::allocateCell<JSC::JSString> (vm=..., size=16) at cache/webkit-a73e665a39b281c5/include/JavaScriptCore/JSCellInlines.h:212 #13 JSC::JSString::create (vm=..., value=...) at cache/webkit-a73e665a39b281c5/include/JavaScriptCore/JSString.h:204 #14 0x0000000004479ad1 in JSC::jsNontrivialString (vm=..., s=...) at vendor/WebKit/Source/JavaScriptCore/runtime/JSString.h:846 #15 JSC::VM::ensureTerminationException (this=0x148296c30000) at vendor/WebKit/Source/JavaScriptCore/runtime/VM.cpp:627 #16 JSGlobalObject__requestTermination (globalObject=<optimized out>) at ./build/release/./src/bun.js/bindings/ZigGlobalObject.cpp:3979 #17 0x0000000003405ab8 in bun.js.web_worker.notifyNeedTermination (this=0x542904f0d80) at /var/lib/buildkite-agent/builds/ip-172-31-16-28/bun/bun/src/bun.js/web_worker.zig:558 #18 0x0000000004362b6f in WebCore::Worker::terminate (this=0x984c900000000000) at ./src/bun.js/bindings/webcore/Worker.cpp:266 #19 WebCore::jsWorkerPrototypeFunction_terminateBody(JSC::JSGlobalObject*, JSC::CallFrame*, WebCore::JSWorker*)::{lambda()#1}::operator()() const (this=<optimized out>) at ./build/release/./src/bun.js/bindings/webcore/JSWorker.cpp:549 #20 WebCore::toJS<WebCore::IDLUndefined, WebCore::jsWorkerPrototypeFunction_terminateBody(JSC::JSGlobalObject*, JSC::CallFrame*, WebCore::JSWorker*)::{lambda()#1}>(JSC::JSGlobalObject&, JSC::ThrowScope&, WebCore::jsWorkerPrototypeFunction_terminateBody(JSC::JSGlobalObject*, JSC::CallFrame*, WebCore::JSWorker*)::{lambda()#1}&&) (lexicalGlobalObject=..., throwScope=..., valueOrFunctor=...) at ./src/bun.js/bindings/webcore/JSDOMConvertBase.h:174 #21 WebCore::jsWorkerPrototypeFunction_terminateBody (lexicalGlobalObject=<optimized out>, callFrame=<optimized out>, castedThis=<optimized out>) at ./build/release/./src/bun.js/bindings/webcore/JSWorker.cpp:549 #22 WebCore::IDLOperation<WebCore::JSWorker>::call<&WebCore::jsWorkerPrototypeFunction_terminateBody, (WebCore::CastedThisErrorBehavior)0> (lexicalGlobalObject=..., operationName=..., callFrame=...) at ./src/bun.js/bindings/webcore/JSDOMOperation.h:63 #23 WebCore::jsWorkerPrototypeFunction_terminate (lexicalGlobalObject=<optimized out>, callFrame=0x7ffe540536b8) at ./build/release/./src/bun.js/bindings/webcore/JSWorker.cpp:554 #24 0x000014825580c038 in ?? () #25 0x00007ffe540537b0 in ?? () #26 0x0000148255a626cb in ?? () #27 0x0000000000000000 in ?? () 1 crashes reported during this test ```
This was referenced Jul 8, 2026
Closed
Jarred-Sumner
added a commit
that referenced
this pull request
Jul 29, 2026
…aking it (#36335) ## Problem `test/cli/install/bun-info.test.ts` (and its sibling `bun-audit.test.ts`) started aborting on the `:debian: 13 x64-asan` PR lane with a LeakSanitizer report after #36175 landed (observed on builds 84674 / 84751 / 84815 / 84881): ``` ==19020==ERROR: LeakSanitizer: detected memory leaks Direct leak of 512 byte(s) in 1 object(s) allocated from: ... #16 in <bun_http::HTTPClient>::clone_metadata src/http/lib.rs:3977:13 #17 in handle_on_data_headers<true> src/http/lib.rs:3761:14 ... #26 in <bun_http::http_thread::HttpThread>::process_events ``` ## Cause `AsyncHTTP::send_sync` wrapped the terminal `HTTPResponseMetadata` in `ManuallyDrop` and returned the inner `picohttp::Response<'static>`: ```rust let metadata = core::mem::ManuallyDrop::new(metadata); Ok(metadata.response) ``` This was carried over from the Zig port (the original `sendSync` returned the bare `Response` and never `deinit`'d the metadata). It leaks two heap allocations per call: the `Box<[Header]>` leaked via `heap::release` in `clone_metadata`, and the `StringBuilder`-owned `owned_buf` that holds status text / header names / header values. Every sync CLI request goes through this path: `bun info` / `bun pm view`, `bun audit`, `bun publish` (up to four times with the OTP retry), `bun upgrade`, `bun create`, and `build --compile`'s target download. LSan's default scan is conservative, treating stacks and registers of every thread as roots. The only live reference to the leaked header slice after the command returns is the `Response` alias stored in `real.response` by `send_sync_callback`, and that lives on a frame already below the main thread's SP when `Global::exit` runs the leak check. Whether LSan still sees it depends on whether a thread happened to park in epoll / a futex with a stale pointer to the slice in a callee-saved register. On the x64-asan PR lane it stopped being hidden after #36175; locally it stays hidden unless registers are excluded as roots. A fix for this leak already exists on the `farm/3977ed4f/linux-arm64-asan-ci` branch (7f1803a) and in #36173; this PR extracts just the leak fix to unblock the x64-asan lane. ## Fix Return the owning `HTTPResponseMetadata` from `send_sync`. Accessor methods (`status_code()`, `status_text()`, `header()`, `header_if_other_is_absent()`) hand out reborrows tied to `&self` so borrowck enforces that no slice escapes the metadata's scope; the inner `Response` is typed `'static` but its slices borrow the sibling `owned_buf` / header slice that `Drop` frees. Callers switch from `res.status_code` / `res.headers.get(..)` to the accessor form. `npm::response_error` now takes `&HTTPResponseMetadata` directly. `send_sync_callback` writes `real.response = None` instead of copying the alias back into the caller's `AsyncHTTP`, since that stored copy would dangle once the returned metadata is dropped and no sync caller reads `self.response`. ## Test Added an ASAN-gated case to `bun-info.test.ts` that runs `bun info` against a local `Bun.serve` registry with `LSAN_OPTIONS=use_registers=0` so the leak is observed deterministically, and asserts a combined `{ stdout, stderr, exitCode }` result with LSan's default non-zero exit left intact. ``` # fail-before (src/ reverted to main, debug build) (fail) bun info does not leak the sync response metadata [5307ms] SUMMARY: AddressSanitizer: 206 byte(s) leaked in 2 allocation(s). # pass-after bun bd test test/cli/install/bun-info.test.ts 20 pass 0 fail (new leak test: 223ms) bun bd test test/cli/install/bun-audit.test.ts # 16 pass bun bd test test/cli/install/bun-create.test.ts # 19 pass bun bd test test/cli/install/bun-upgrade.test.ts # 8 pass ``` <!-- robobun:evidence:begin --> --- **[review]** gate passed · iteration 1 · 10 files touched <details><summary>fails on main (without fix)</summary> ```console ASAN without fix: 1 FAILED $ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/cli/install/bun-info.test.ts bun test v1.4.0 (8f0ef47) test/cli/install/bun-info.test.ts: (pass) bun info > bun info (main command) > should display package info for latest version [359.12ms] (pass) bun info > bun info (main command) > should handle missing arguments [346.80ms] (pass) bun info > bun info (main command) > should display package info for specific version [402.47ms] (pass) bun info > bun pm view (alias) > should display package info for latest version [380.58ms] (pass) bun info > bun info (main command) > should display specific property [484.38ms] (pass) bun info > bun pm view (alias) > should display package info for specific version [380.99ms] (pass) bun info > bun pm view (alias) > should display nested property [324.88ms] (pass) bun info > bun pm view (alias) > should handle non-existent package [297.70ms] (pass) bun info > bun pm view (alias) > should display specific property [1379.12ms] (pass) bun info > bun pm view (alias) > should output JSON format with --json flag [1356.80ms] (pass) bun info > bun pm v ... (truncated) release without fix: 1 skipped bun test v1.4.0-canary.1 (b4544d0) test/cli/install/bun-info.test.ts: (pass) bun info > bun info (main command) > should display package info for latest version [69.02ms] (pass) bun info > bun info (main command) > should handle missing arguments [68.71ms] (pass) bun info > bun pm view (alias) > should handle non-existent package [62.61ms] (pass) bun info > bun pm view (alias) > should display package info for latest version [71.24ms] (pass) bun info > bun pm view (alias) > should display nested property [69.87ms] (pass) bun info > bun pm view (alias) > should handle . [61.86ms] (pass) bun info > bun info (main command) > should display package info for specific version [75.65ms] (pass) bun info > bun info (main command) > should display specific property [77.38ms] (pass) bun info > bun pm view (alias) > should output JSON format with --json flag [78.60ms] (pass) bun info > bun pm view (alias) > versions[0] should work [71.64ms] (pass) bun info > bun pm view (alias) > versions should work [75.43ms] (pass) bun info > bun pm view (alias) > should handle dist-tags like latest [74.19ms] (pass) bun info > bun pm view (alias) > should handle version ranges [78.07ms] (p ... (truncated) ``` </details> <details><summary>passes on PR (with fix)</summary> ```console ASAN with fix: all passed $ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/cli/install/bun-info.test.ts bun test v1.4.0 (8f0ef47) test/cli/install/bun-info.test.ts: (pass) bun info > bun info (main command) > should display package info for latest version [349.74ms] (pass) bun info > bun info (main command) > should display package info for specific version [468.60ms] (pass) bun info > bun info (main command) > should display specific property [469.69ms] (pass) bun info > bun info (main command) > should handle missing arguments [475.25ms] (pass) bun info > bun pm view (alias) > should display package info for latest version [506.84ms] (pass) bun info > bun pm view (alias) > should display package info for specific version [460.48ms] (pass) bun info > bun pm view (alias) > should display nested property [392.82ms] (pass) bun info > bun pm view (alias) > should display specific property [507.04ms] (pass) bun info > bun pm view (alias) > should handle non-existent package [458.13ms] (pass) bun info > bun pm view (alias) > should output JSON format with --json flag [575.15ms] (pass) bun info > bun pm vie ... (truncated) release with fix: 1 skipped $ bun scripts/build.ts --profile=release [configured] bun-profile → bun (stripped) in 1113ms (unchanged) ninja: Entering directory `/workspace/bun/build/release' [1/6] gen generated_host_exports.rs generated_host_exports.rs: 94 exports (host=3, lazy=10, generic=81, rust=0); 240 extern-C blocks audited [1/6] cargo bun_bin → libbun_rust.a (--target x86_64-unknown-linux-gnu) nightly-2026-07-20-x86_64-unknown-linux-gnu unchanged - rustc 1.99.0-nightly (9f36de775 2026-07-19) �[1m�[92m Compiling�[0m bun_core v0.0.0 (/workspace/bun/src/bun_core) �[1m�[92m Compiling�[0m bun_errno v0.0.0 (/workspace/bun/src/errno) �[1m�[92m Compiling�[0m bun_ptr v0.0.0 (/workspace/bun/src/ptr) �[1m�[92m Compiling�[0m bun_boringssl_sys v0.0.0 (/workspace/bun/src/boringssl_sys) �[1m�[92m Compiling�[0m bun_safety v0.0.0 (/workspace/bun/src/safety) �[1m�[92m Compiling�[0m bun_zlib_sys v0.0.0 (/workspace/bun/src/zlib_sys) �[1m�[92m Compiling�[0m bun_cares_sys v0.0.0 (/workspace/bun/src/cares_sys) �[1m�[92m Compiling�[0m bun_zstd v0.0.0 (/workspace/bun/src/zstd) �[1m�[92m Compiling�[0m bun_collections v0.0.0 (/workspace/bun/src/collections) �[1m�[92m Compiling�[0m bun_p ... (truncated) ``` </details> <details><summary>diff hotspot</summary> ``` src/http/AsyncHTTP.rs | 12 +++-- src/http/lib.rs | 22 +++++++++ src/install/npm.rs | 23 +++++----- src/runtime/cli/audit_command.rs | 4 +- src/runtime/cli/create_command.rs | 14 +++--- src/runtime/cli/pm_view_command.rs | 2 +- src/runtime/cli/publish_command.rs | 28 +++++------- src/runtime/cli/upgrade_command.rs | 4 +- src/standalone_graph/StandaloneModuleGraph.rs | 2 +- test/cli/install/bun-info.test.ts | 65 +++++++++++++++++++++++++-- 10 files changed, 125 insertions(+), 51 deletions(-) ``` </details> **gate history** · 2 passed · 1 rejected · iteration 1 <details><summary>evidence per changed file</summary> ``` file reads edits tests src/http/AsyncHTTP.rs 5 6 0 src/http/lib.rs 5 4 0 src/install/npm.rs 0 0 0 src/runtime/cli/audit_command.rs 1 0 0 src/runtime/cli/create_command.rs 2 0 0 src/runtime/cli/pm_view_command.rs 2 0 0 src/runtime/cli/publish_command.rs 2 0 0 src/runtime/cli/upgrade_command.rs 1 0 0 src/standalone_graph/StandaloneModuleGraph.rs 1 0 0 test/cli/install/bun-info.test.ts 6 11 0 ``` </details> <!-- robobun:evidence:end --> --------- Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This was referenced Aug 13, 2026
Jarred-Sumner
added a commit
that referenced
this pull request
Aug 24, 2026
) (#40138) ### What does this PR do? Bumps mimalloc to oven-sh/mimalloc#27, which combines oven-sh/mimalloc#22–#26 and replaces their per-reader fixes with one teardown protocol for `mi_heap_delete` / `mi_heap_destroy`. The problem those PRs were circling: a heap is torn down while a concurrent cross-thread `mi_free`, or a thread that used the heap earlier and still caches a theap for it, can reach it. The hole in the middle was that the deleter claimed pages by *writing* to them (`atomic_or` of the owned bit) with nothing pinning the page, so a concurrent free could release the page and the slice be reused in between. Now: detach theaps → abandon their pages as thread-exit does → pin-then-claim every abandoned page (the same bitmap-as-pin protocol the abandoned-page map already uses) → free theaps → free heap. Details, contract and tests in the mimalloc PR. Also in the bump: mimalloc#22 (THP opt-out only when the system setting is `always` — saves a `madvise` per mmap on Debian/Ubuntu defaults), from mimalloc#23 only the scavenger signal mask (a fault on that thread produced no crash report), the scavenger thread starting lazily (a single-threaded `bun -e` no longer spawns it: −1 thread, −24 syscalls), and targeted upstream dev3 fixes (thread-locals-after-free guard, #1364, #1371, NUMA node count). Upstream's in-progress page-meta layout rework is deliberately *not* included. **What this does not do:** fix the Windows corrupted-free-list crash family (BUN-40BH and siblings). Those lists are written by Bun — #39897 (file read completing into a freed buffer, merged) and #39643 (poll handle freed twice from a nested event loop, open) — and mimalloc is only where the damage surfaces. #23's "validate links and cut the list" is not taken for that reason: it would keep running past the write and hide it. ### How did you verify your code works? - mimalloc `ctest`: Release 23/23, Debug (`MI_DEBUG_FULL`) 24/24 (was 20/21 on the old pin), ASAN 22/22, TSAN 19/19 with 0 reports (see mimalloc#27). - `bun bd test`: transpiler (190/190), bundler_edgecase (138/138), bundler_minify (43/43), css (2358 pass; 6 debug-timeout fuzz tests), workers/serve (same 4 failures as a `main` debug build on this box). - Release x64, n=7 interleaved, old pin vs new pin on the same Bun commit: | | old pin median (range) | new pin median (range) | Δ | |---|---|---|---| | `bun -e 1` peak RSS | 27024 KB (26564–27088) | 26016 KB (25984–26020)¹ | −3.7% | | `bun -e 1` syscalls | 270 | 246 | −24 (no `clone3` for the scavenger, −6 `rt_sigprocmask`, −5 `madvise`) | | `Bun.serve` hello RSS after 200k req (c=64) | 49760 KB (48540–50040) | 47948 KB (46384–48252) | −3.6% | | `bun build --minify --sourcemap` three.js×10 peak | 345696 KB (340672–348928) | 343724 KB (339612–348828) | −0.6% (overlaps) | ¹ one run at 17212 KB excluded from the range as an outlier. The first two rows come from the scavenger thread now starting on first use (first park / first scheduled purge) instead of at process init — a change made because the eager start aborted macOS processes that `DYLD_INSERT` the dylib (thread created before libobjc initializes); `bun -e 1` never needs it. Before that change the same A/B was flat (+0.1–0.3%, overlapping), so the teardown protocol itself is RSS-neutral as forecast.
dylan-conway
added a commit
that referenced
this pull request
Sep 21, 2026
…t from what the stack scan marks (#43224) ### What does this PR do? Makes `test/js/bun/module-graph/module-graph-gc.test.ts` independent of what is lying on the native stack, which is why it fails on Windows (every run on a Windows 11 machine, and regularly on the Windows 2019 CI lane, on `main` and on unrelated branches). The helpers read "the FinalizationRegistry callback has not run" as "something keeps it alive". With a conservative collector that is not the same thing: a word on the native stack that happens to point at a cell keeps it marked. On Windows, timers fire from inside libuv's `uv_run`, so `uv_run`'s and `on_uv_timer`'s frames are live during every collection these tests run, laid over stack that earlier callbacks used, and a slot such a frame never writes still holds a cell of those callbacks' frames. The tests now ask the question they mean. `Lifetimes` records each tracked object's cell. `stillAlive()` still goes by finalization first; a name that is still not finalized after a few collections is looked up in the debugging heap snapshot and counts as kept only when a root reaches its cell, and the failure report is the path from that root. `settle()` likewise uses `heapStats()` counts and falls back to the number of cells of a type that a root reaches only when the counts stay over a limit. The snapshot has every heap edge and every root (strong references, strong handles, protected values) and no entry for stack words, so a real retainer shows up with its path and a stale stack word does not show up at all. It is taken from a timer callback with the awaiting test suspended and its promise held from module scope, so what the test's own frames hold is held through the heap like everything else. A snapshot takes about 2 s on a debug+ASAN build, which is why it is only taken for what finalization did not settle: on that build the passing path takes none and the file runs as long as it does on `main`. `survives()` is unchanged (not finalized after a few collections); the one assertion that a graph does *not* survive now asks `stillAlive()`. The Intel macOS `todoIf` on the repeating-timer test is removed: its comment described exactly the unrooted cycle these helpers no longer count as kept alive. Asking about a name that was never tracked throws. ### Evidence that the stack is what held these graphs Release build of `main`, Windows 11, a test stuck with its graph not finalized after the bounded collections: Heap snapshot (the test's own failure report): the graph is in a cycle that nothing outside it points at and no root reaches. ``` ModuleGraph#605: island of 16 cells (ModuleGraph, InternalFieldTuple, JSLexicalEnvironment, AsyncContextFrame, ModuleLoader, JSModuleEnvironment, Timeout, ModuleRecord, ModuleRegistryEntry, Function(tick), ModuleNamespaceObject, Promise, Function); nothing in the heap points at: (none: a cycle) ModuleGraph#605: no root reaches it; held from InternalFieldTuple Internal:0, InternalFieldTuple Internal:0, JSLexicalEnvironment Variable:moduleGraph ``` Debugger (lldb attached while stuck; the address of every cell of that cycle, taken from the snapshot, searched for between the main thread's stack pointer and its stack base): one hit, the imported module's `JSModuleEnvironment`, at offset 8 of `on_uv_timer`'s frame. ``` CELLS ModuleGraph=0x21fa50e1048 ... JSModuleEnvironment=0x21fa4f50360 ... data found at location: 0x92455cd898 0x92455cd898: 60 03 f5 a4 1f 02 00 00 00 d9 5c 45 92 00 00 00 rsp 0x00000092455cd890 #24 bun_runtime::timer::All::on_uv_timer (#22 EventLoopTimer::fire and #23 drain_timers inlined) rsp 0x00000092455cd940 #25 uv__run_timers rsp 0x00000092455cd9a0 #26 uv_run rsp 0x00000092455ceab0 #27 bun_uws_sys::loop_::WindowsLoop::tick_with_timeout ``` In a standalone script (one graph importing one module, then collections from timers only) the same search finds the module namespace three times inside `uv_run`'s own frame (`0x...58e0`–`0x...69e0`, which holds `uv__poll`'s uninitialized `OVERLAPPED_ENTRY overlappeds[128]`), next to JIT return addresses. Running one `setImmediate`, which the loop runs from outside `uv_run` and so over that stack, lets the graph go in the next collection. ### How did you verify your code works? Release builds of `main`, the file run repeatedly: | | before | after | |---|---|---| | Windows 11 x64 | 0 of 8 | 8 of 8 | | macOS arm64 | 6 of 6 | 6 of 6 | | Linux x64 | passes | 3 of 3 | The helpers still catch a real leak: with a test changed to keep its graph in an array on `globalThis`, it fails with `graph: root(ProtectedValues) GlobalObject -Property:leakedOnPurpose-> Array -Index:0-> ModuleGraph`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds: conditional builds in makefile
Fixes: incorrect imports of 'JavaScriptCore.zig' (note the caps 's')
replaces with correct import of 'JavascriptCore.zig'