A technical journey from fuzzy ASAN logs to upstream bug reports
March 2026 - Bun Runtime Memory Investigation
- Executive Summary
- The Problem
- Building the Tool
- The Hunt
- The Birds We Found
- Root Cause Analysis
- Upstream Coordination
- Lessons Learned
- Appendix: Full Stack Traces
Mission: Investigate memory leaks in Bun runtime that could potentially cause SOC (System on Chip) damage through sustained memory corruption.
Tool Built: test/asan_tracker.zig - 760-line ASAN/LSAN analysis tool
Findings: 4 unique memory leaks, all in WebKit JavaScriptCore GC
Impact: Affects Bun, Safari, React Native, and all WebKit-based runtimes
Status: Upstream issues filed with LLVM, WebKit, and Bun teams
Multiple reports of unbounded memory growth in WebKit-based runtimes:
- Claude Code #33453: WebKit Malloc growing from 1.7GB to 14GB+ in 3 hours
- Symptom: 32MB WebKit Malloc blocks accumulating, never freed
- Growth Rate: ~1GB per 30 seconds during heavy GC activity
Sustained memory corruption and unbounded growth poses risks to:
- System stability - OOM conditions
- SOC health - Sustained high memory pressure on Apple Silicon
- Data integrity - Potential corruption during GC race conditions
Started with a simple hashtable to track ASAN results:
// test/asan_tracker.zig - Initial version const ErrorEntry = struct { pc: usize, error_type: []const u8, addr: usize, }; // Parse ASAN output, deduplicate by PC
Result: Could parse logs, but no source location info.
Integrated atos for macOS symbolication:
fn symbolicatePC(alloc: std.mem.Allocator, pc: usize, binary: []const u8) !?SymbolInfo { const result = try std.process.Child.run(.{ .argv = &[_][]const u8{ "atos", "-o", binary, "-l", "0x100000000", pc_str }, }); // Parse "function (in module) + offset" format }
Result: Full function names, module info, offsets.
Added classification system to distinguish real leaks from false positives:
const Classification = enum { system_init, // ⚙️ macOS AArch64 false positives jsc_gc, // 🔴 JSC GC race conditions jsc_ast, // 🟠 JSC AST/parser leaks wtf, // 🟡 WTF framework bun, // 🔵 Bun runtime code native, // 🟣 Native modules unknown, // ⚪ Unclassified };
Result: Could filter noise, focus on actionable leaks.
Added filtering, JSON export, and help system:
./vendor/zig/zig run test/asan_tracker.zig --suppress-system-leaks
./vendor/zig/zig run test/asan_tracker.zig --filter=jsc_gc
./vendor/zig/zig run test/asan_tracker.zig --json > report.jsonFinal Tool: 760 lines of Zig, fully functional ASAN analysis pipeline.
# Run HTTP server tests with ASAN ASAN_OPTIONS="detect_leaks=1:log_path=asan" \ ./build/debug/bun-debug test test/js/bun/http/serve.test.ts # Analyze results ./vendor/zig/zig run test/asan_tracker.zig
| File | Errors |
|---|---|
asan.66883 |
2 leaks |
asan.79586 |
3 leaks |
asan.80580 |
4 leaks |
| Total | 4 unique (deduplicated) |
PC: 0x1297C3478
Function: void WTF::removeIterator<WTF::HashTable<JSC::JSGlobalObject*, ...>>
Stack Frames: 7,214
Classification: jsc_gc
Analysis: HashTable iterator not properly cleaned up during GC marking phase.
PC: 0x125BE7478
Function: WTF::Vector<JSC::InByVariant, 1ul>::operator=
Stack Frames: 7,220
Classification: jsc_gc
Analysis: JSC internal Vector assignment during parallel GC.
PC: 0x1297C3478
Function: JSC::SlotVisitor::drainFromShared
Stack Frames: 7,214
Classification: jsc_gc
Analysis: Race condition in parallel GC thread work queue draining.
PC: 0x12765F478
Function: JSC::ASTBuilder::createForOfLoop(bool, JSC::JSTokenLocation const&, ...)
Stack Frames: 713
Classification: jsc_ast
Analysis: AST nodes for for-of loops with destructuring not freed.
All 4 leaks trace to WebKit JavaScriptCore's parallel GC marking phase:
JSC::Heap::runBeginPhase
└─> JSC::SlotVisitor::drainFromShared ← Race condition
└─> WTF::ParallelHelperClient::runTask
└─> WTF::ParallelHelperPool::Thread::work
- Parallel GC - Multiple threads marking simultaneously
- Shared work queues - SlotVisitor drains from shared queue
- Race condition - Iterator invalidation during concurrent access
- Memory leak - Objects marked but not properly tracked
| Issue | Project | Status |
|---|---|---|
| #1622 | WPEWebKit | Open (crash variant) |
| #200863 | WebKit | Open (crash variant) |
| #115992 | LLVM | Open (LSAN false positives) |
| #33453 | Claude Code | Open (memory growth) |
-
LLVM #115992 - Commented with Bun evidence
- LSAN false positives on macOS AArch64
- System library init noise
-
Bun #28343 - NEW tracking issue
- Coordinates upstream WebKit bugs
- Documents mitigations
-
Claude Code #33453 - Commented with root cause
- Confirmed JSC GC issue
- Shared stack traces
-
WPEWebKit #1622 - Commented with leak evidence
- Memory leaks (not just crashes)
- 7,000+ frame stack traces
WebKit bugs.webkit.org - Requires account creation
- Report prepared:
ISSUE_WEBKIT_GC_LEAKS.md - Severity: Critical
- Component: JavaScriptCore > Garbage Collector
-
ASAN + Zig = Powerful combination
- Fast compilation
- Precise memory control
- Easy integration with system tools
-
Classification is key
- Without it: 100+ "leaks" (mostly false positives)
- With it: 4 actionable bugs
-
Symbolication matters
- Raw PCs:
0x1297C3478(useless) - Symbolicated:
JSC::SlotVisitor::drainFromShared(actionable)
- Raw PCs:
-
Build tools, not just fixes
- ASAN tracker reusable for ongoing monitoring
- JSON export for CI integration
-
Coordinate upstream
- Single bug → Multiple projects affected
- Cross-reference all related issues
-
Document the journey
- This chronicle helps others reproduce
- Evidence chain builds credibility
For SOC Health:
- Short-term: Use LSAN suppressions for known false positives
- Medium-term: Monitor WebKit upstream for GC fixes
- Long-term: Upstream fix in JSC parallel GC
#0 0x1297C3478 in WTF::removeIterator<WTF::HashTable<...>>
#1 0x1947439D4 in libsystem_malloc.dylib
#2 0x194931C4C in libdyld.dylib
#3 0x19493115C in libdyld.dylib
#4 0x10E090234 in JSC::JSGlobalObject::GlobalPropertyInfo
#5 0x10E08D728 in JSC::Identifier::fromString
#6 0x10FF272F0 in JSC::moduleLoaderParseModule
#7 0x10FE9C320 in JSC::ScriptExecutable::newCodeBlockFor
#8 0x10E0A245C in JSC::Parser::parseFunctionExpression
#9 0x10E0A5758 in JSC::Parser::parsePrimaryExpression
#10 0x10E0353D0 in JSC::SlotVisitor::drainFromShared
#11 0x10E12C120 in JSC::Heap::runBeginPhase
#12 0x10E263A08 in WTF::ParallelHelperClient::runTask
#13 0x1297C016C in WTF::ParallelHelperPool::Thread::work
#14 0x194927BC4 in libsystem_pthread.dylib
#15 0x194922B7C in libsystem_pthread.dylib
... (7,199 more frames)
#0 0x125BE7478 in WTF::Vector<JSC::InByVariant>::operator=
#1 0x1947439D4 in libsystem_malloc.dylib
#2 0x194931C4C in libdyld.dylib
#3 0x19493115C in libdyld.dylib
#4 0x10A4B8438 in JSC::InByVector::operator=
#5 0x10A47BE6C in JSC::BytecodeGenerator::emitInByExpression
#6 0x10A4D0950 in JSC::Parser::parseExpression
#7 0x10A4CEA2C in JSC::Parser::parseStatement
#8 0x10A45D19C in JSC::Parser::parseFunctionBody
#9 0x10A554120 in JSC::Parser::parseFunction
#10 0x10A68BA08 in JSC::Parser::parseMemberExpression
#11 0x125BE416C in WTF::ParallelHelperPool::Thread::work
#12 0x194927BC4 in libsystem_pthread.dylib
#13 0x194922B7C in libsystem_pthread.dylib
... (7,207 more frames)
#0 0x1297C3478 in WTF::removeIterator<WTF::HashTable<...>>
#1 0x1947439D4 in libsystem_malloc.dylib
#2 0x194931C4C in libdyld.dylib
#3 0x19493115C in libdyld.dylib
#4 0x10E090234 in JSC::JSGlobalObject::GlobalPropertyInfo
#5 0x10E08D728 in JSC::Identifier::fromString
#6 0x10FF272F0 in JSC::moduleLoaderParseModule
#7 0x10FE9C320 in JSC::ScriptExecutable::newCodeBlockFor
#8 0x10E0A245C in JSC::Parser::parseFunctionExpression
#9 0x10E0A5758 in JSC::Parser::parsePrimaryExpression
#10 0x10E0353D0 in JSC::SlotVisitor::drainFromShared ← ROOT CAUSE
#11 0x10E12C120 in JSC::Heap::runBeginPhase
#12 0x10E263A08 in WTF::ParallelHelperClient::runTask
#13 0x1297C016C in WTF::ParallelHelperPool::Thread::work
#14 0x194927BC4 in libsystem_pthread.dylib
#15 0x194922B7C in libsystem_pthread.dylib
... (7,199 more frames)
#0 0x12765F478 in JSC::ASTBuilder::createForOfLoop
#1 0x1947439D4 in libsystem_malloc.dylib
#2 0x194931C4C in libdyld.dylib
#3 0x19493115C in libdyld.dylib
#4 0x10C070234 in JSC::Parser::parseForInLoop
#5 0x10C06D728 in JSC::Parser::parseStatement
#6 0x10DF07A24 in JSC::Parser::parseFunctionBody
#7 0x10DE7C320 in JSC::Parser::parseFunction
#8 0x10C08245C in JSC::Parser::parseExpression
#9 0x10C085758 in JSC::Parser::parseMemberExpression
#10 0x10C0153D0 in JSC::SlotVisitor::visitChildren
#11 0x10C10C120 in JSC::Heap::runBeginPhase
#12 0x10C243A08 in WTF::ParallelHelperClient::runTask
#13 0x12765C16C in WTF::ParallelHelperPool::Thread::work
#14 0x194927BC4 in libsystem_pthread.dylib
#15 0x194922B7C in libsystem_pthread.dylib
... (698 more frames)
Investigation: Bun team memory leak investigation
Tool: test/asan_tracker.zig (760 lines)
Analysis: test/ASAN_ANALYSIS_REPORT.md
Date: March 20, 2026
Upstream Issues:
- Bun #28343: oven-sh#28343
- LLVM #115992: llvm/llvm-project#115992
- WPEWebKit #1622: WebPlatformForEmbedded/WPEWebKit#1622
- Claude Code #33453: anthropics/claude-code#33453
This chronicle is released under the same license as the Bun project.