Skip to content

All deps now build on linux - #27

Merged
Jarred-Sumner merged 1 commit into
oven-sh:mainfrom
DAlperin:main
Sep 18, 2021
Merged

Jarred-Sumner merged 1 commit into
oven-sh:mainfrom
DAlperin:main

Conversation

@DAlperin

Copy link
Copy Markdown
Contributor

Move CC and CXX into variables
Fix some capitalization
+A few other portability improvements

Move CC and CXX into variables
Fix some capitalization
+A few other portability improvements
@DAlperin

Copy link
Copy Markdown
Contributor Author

@Jarred-Sumner
Jarred-Sumner merged commit 7c05bb7 into oven-sh:main Sep 18, 2021
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
```
airgap added a commit to airgap/parabun that referenced this pull request Apr 18, 2026
Jarred-Sumner pushed a commit that referenced this pull request Jul 23, 2026
…and empty <failure> (#34975)

### What does this PR do?

Fixes three problems with the JUnit XML reporter that, together, made
the report unparseable and stripped of any useful failure information.

#### Repro

```sh
cat > x.test.js <<'JS'
describe('suite <a> & "b"', () => {
  test("plain fail", () => { throw new Error("boom: important message"); });
  test("ctrl \x00nul\x1besc", () => { throw new Error("x"); });
});
JS
bun test --reporter=junit --reporter-outfile=r.xml
python3 -c "import xml.etree.ElementTree as ET; ET.parse('r.xml')"
# xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 8, column 36
```

#### 1. Control characters in test names produce malformed XML

`escape_xml` wrote `&#N;` for every C0 control byte but neither flushed
the pending run nor advanced `last`, so the raw byte was *also* emitted,
and the references appeared at the start of the string instead of in
place. Since bytes 0x00..=0x08 / 0x0B / 0x0C / 0x0E..=0x1F are not legal
XML 1.0 `Char`s even as numeric references, the fix passes TAB/LF/CR
through and drops every other C0 byte.

Before: `name="&#0;&#27;ctrl ^@nul^[esc"` (parse error).
After: `name="ctrl nulesc"` (parses).

#### 2. `classname` is double-escaped

The describe-scope names were XML-escaped while being joined with `"
&gt; "`, then escaped again inside `write_test_case`, so
`describe('suite <a> & "b"')` produced `classname="suite
&amp;lt;a&amp;gt; &amp;amp; &amp;quot;b&amp;quot;"`. The inner
`<testsuite name="">` was only escaped once, so the two disagreed. The
join now concatenates the raw names with a raw `" > "` separator and
leaves the single escape to `write_test_case`.

#### 3. `<failure>` carries no message, stack, or correct type

Every thrown error was reported as `<failure type="AssertionError" />`
with no message or stack. `on_uncaught_exception` now records the
error's name, message, and a colourless `print_errorlike_object`
rendering on the `JunitReporter`; `write_test_case` emits them as the
`type` and `message` attributes and the element body:

```xml
<failure type="Error" message="boom: important message">1 | describe(...
   ...
error: boom: important message
      at &lt;anonymous&gt; (x.test.js:3:71)
</failure>
```

`TypeError`, `RangeError`, etc. now report their real name in `type`.
Timeouts also gain `message="test timed out"`.

### How did you verify your code works?

New tests in `test/js/junit-reporter/junit.test.js`:

- `produces well-formed XML when test names contain control characters`:
asserts the raw bytes contain no illegal C0 characters, no
`&#0;`/`&#27;`, the report parses with a strict XML parser, and TAB/LF
survive.
- `escapes the classname attribute exactly once`: asserts no `&amp;lt;`
/ `&amp;amp;` etc. appear and the decoded `classname` round-trips to the
original describe titles.
- `includes the error type, message and stack in <failure>`: asserts
`type`/`message` and body text for a plain `Error`, a `TypeError`, and
an `expect().toBe()` failure, and that no ANSI escapes leak into the
report.

All three fail against `main` and pass with this change. The existing
`junit reporter` tests and the `--parallel --reporter=junit` tests still
pass.

<!-- robobun:evidence:begin -->

---

**[review]** gate passed · iteration 5 · 6 files touched

<details><summary>fails on main (without fix)</summary>

```console
ASAN without fix: BUILD FAILED (no junit output)
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/js/junit-reporter/junit.test.js
ninja: Entering directory `/workspace/bun/build/debug'
[1/184] gen bindgenv2
[2/184] gen bake.{client,server,error}.js
-> bake.client.js, bake.server.js, bake.error.js
[3/184] gen generated_host_exports.rs
generated_host_exports.rs: 91 exports (host=3, lazy=10, generic=78, rust=0); 240 extern-C blocks audited
[4/184] gen cpp.rs (cppbind)
[5/184] gen ZigGeneratedClasses.{cpp,h,rs}
Found 2 classes from /workspace/bun/src/jsc/resolve_message.classes.ts
  - ResolveMessage (13 fields)
  - BuildMessage (10 fields)
Found 1 classes from /workspace/bun/src/runtime/api/Archive.classes.ts
  - Archive (4 fields, 1 class fields)
Found 2 classes from /workspace/bun/src/runtime/api/BunObject.classes.ts
  - ResourceUsage (8 fields)
  - Subprocess (20 fields)
Found 1 classes from /workspace/bun/src/runtime/api/cron.classes.ts
  - CronJob (5 fields)
Found 3 classes from /workspace/bun/src/runtime/api/filesystem_router.classes.ts
  - FileSystemRouter (5 fields)
  - FrameworkFileSystemRouter (2 fields)
  - MatchedRoute
... (truncated)

release without fix: 6 FAILED
bun test v1.4.0-canary.1 (1498d7b)

test/js/junit-reporter/junit.test.js:
(pass) junit reporter > should generate valid junit xml for passing tests %s [20.52ms]
(pass) junit reporter > should generate valid junit xml for passing tests %s [15.13ms]
/tmp/junit-comprehensive_5eGMij
253 |       stderr: "pipe",
254 |     });
255 |     await proc1.exited;
256 | 
257 |     const xmlContent1 = await file(junitPath1).text();
258 |     expect(filterJunitXmlOutput(xmlContent1)).toMatchSnapshot();
                                                    ^
error: expect(received).toMatchSnapshot(expected)

@@ -2,26 +2,26 @@
  "
  
    
      
        
-         
+         
        
        
-         
+         
        
        
-         
+         
        
        
-         
+         
            
          
        
        
        
-         AssertionError: expect(received).toBe(expected)&#10;&#10;Expected: 3&#10;Received: 2&#10;&#10;      at comprehensive.test.js:31:27&#10;
+         
        
        
          
        
        

- Expected  - 5
+ Received  + 5

      at <anonymous> (/workspace/bun/test/js/junit-reporter/junit.test.js:258:47)
(fail) junit reporter > mor
... (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/js/junit-reporter/junit.test.js
bun test v1.4.0 (a93ab8b)

test/js/junit-reporter/junit.test.js:
(pass) junit reporter > should generate valid junit xml for passing tests %s [796.77ms]
(pass) junit reporter > should generate valid junit xml for passing tests %s [576.89ms]
/tmp/junit-comprehensive_Py8zho
(pass) junit reporter > more scenarios [1138.97ms]
(pass) junit reporter > should report only the final result for a retried test [652.04ms]
(pass) junit reporter > produces well-formed XML when test names contain control characters [531.82ms]
(pass) junit reporter > escapes the classname attribute exactly once [467.97ms]
(pass) junit reporter > keeps the test body's error in <failure> when afterEach also throws [456.76ms]
(pass) junit reporter > includes the error type, message and stack in <failure> [525.69ms]

 8 pass
 0 fail
 2 snapshots, 135 expect() calls
Ran 8 tests across 1 file. [8.06s]
__F:0:S:0

release with fix: all passed
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped) in 882ms (unchanged)
ninja: Entering directory `/workspace/bun/build/release'
[1/142] gen bindgenv2
[2/142] gen bake.{client,server,error}.js
-> bake.client.js, bake.server.js, bake.error.js
[3/142] gen generated_host_exports.rs
generated_host_exports.rs: 91 exports (host=3, lazy=10, generic=78, rust=0); 244 extern-C blocks audited
[4/142] gen cpp.rs (cppbind)
[5/142] gen ZigGeneratedClasses.{cpp,h,rs}
Found 2 classes from /workspace/bun/src/jsc/resolve_message.classes.ts
  - ResolveMessage (13 fields)
  - BuildMessage (10 fields)
Found 1 classes from /workspace/bun/src/runtime/api/Archive.classes.ts
  - Archive (4 fields, 1 class fields)
Found 2 classes from /workspace/bun/src/runtime/api/BunObject.classes.ts
  - ResourceUsage (8 fields)
  - Subprocess (20 fields)
Found 1 classes from /workspace/bun/src/runtime/api/cron.classes.ts
  - CronJob (5 fields)
Found 3 classes from /workspace/bun/src/runtime/api/filesystem_router.classes.ts
  - FileSystemRouter (5 fields)
  - FrameworkFileSystemRouter (2 fields)
  - MatchedRoute (8 fields)
Found 1 classes from /workspace/bun/src/runtime/ap
... (truncated)
```

</details>

<details><summary>diff hotspot</summary>

```
src/jsc/VirtualMachine.rs                          |  10 ++
 src/runtime/cli/test_command.rs                    | 181 +++++++++++++++++++--
 src/runtime/test_runner/Execution.rs               |  18 ++
 src/runtime/test_runner/bun_test.rs                |  27 ++-
 .../__snapshots__/junit.test.js.snap               |  18 +-
 test/js/junit-reporter/junit.test.js               | 172 +++++++++++++++++++-
 6 files changed, 401 insertions(+), 25 deletions(-)
```

</details>

**gate history** · 6 passed · 1 rejected · iteration 5

<details><summary>evidence per changed file</summary>

```
file                                                     reads  edits  tests
src/jsc/VirtualMachine.rs                                    8      2      0
src/runtime/cli/test_command.rs                             12     14      0
src/runtime/test_runner/Execution.rs                         4      3      0
src/runtime/test_runner/bun_test.rs                          6      8      0
test/js/junit-reporter/__snapshots__/junit.test.js.snap      0      0      0
test/js/junit-reporter/junit.test.js                         7     16      0
```

</details>

<!-- robobun:evidence:end -->
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants