GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bun/test/ASAN_INVESTIGATION_CHRONICLE.md at main · jnorthrup/bun

Expand file tree

/

ASAN_INVESTIGATION_CHRONICLE.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
400 lines (294 loc) · 11 KB
/

ASAN_INVESTIGATION_CHRONICLE.md

Copy path

File metadata and controls

400 lines (294 loc) · 11 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

🩺 ASAN Investigation Chronicle: Hunting JavaScriptCore GC Memory Leaks

A technical journey from fuzzy ASAN logs to upstream bug reports

March 2026 - Bun Runtime Memory Investigation


📖 Table of Contents

  1. Executive Summary
  2. The Problem
  3. Building the Tool
  4. The Hunt
  5. The Birds We Found
  6. Root Cause Analysis
  7. Upstream Coordination
  8. Lessons Learned
  9. Appendix: Full Stack Traces

Executive Summary

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


The Problem

Initial Reports

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

The Risk

Sustained memory corruption and unbounded growth poses risks to:

  1. System stability - OOM conditions
  2. SOC health - Sustained high memory pressure on Apple Silicon
  3. Data integrity - Potential corruption during GC race conditions

Building the Tool

Phase 1: Quick & Dirty Parser

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.

Phase 2: Adding DWARF Symbolication

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.

Phase 3: Leak Classification

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.

Phase 4: CLI & Export

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.json

Final Tool: 760 lines of Zig, fully functional ASAN analysis pipeline.


The Hunt

Test Execution

# 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

Files Scanned

File Errors
asan.66883 2 leaks
asan.79586 3 leaks
asan.80580 4 leaks
Total 4 unique (deduplicated)

The Birds We Found

Leak #1: HashTable Iterator Removal 🔴

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.

Leak #2: Vector Assignment 🔴

PC: 0x125BE7478
Function: WTF::Vector<JSC::InByVariant, 1ul>::operator=
Stack Frames: 7,220
Classification: jsc_gc

Analysis: JSC internal Vector assignment during parallel GC.

Leak #3: SlotVisitor Race 🔴

PC: 0x1297C3478
Function: JSC::SlotVisitor::drainFromShared
Stack Frames: 7,214
Classification: jsc_gc

Analysis: Race condition in parallel GC thread work queue draining.

Leak #4: For-Of AST 🟠

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.


Root Cause Analysis

The Common Thread

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

Why This Matters

  1. Parallel GC - Multiple threads marking simultaneously
  2. Shared work queues - SlotVisitor drains from shared queue
  3. Race condition - Iterator invalidation during concurrent access
  4. Memory leak - Objects marked but not properly tracked

Related Upstream Issues

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)

Upstream Coordination

Issues Filed/Commented

  1. LLVM #115992 - Commented with Bun evidence

    • LSAN false positives on macOS AArch64
    • System library init noise
  2. Bun #28343 - NEW tracking issue

    • Coordinates upstream WebKit bugs
    • Documents mitigations
  3. Claude Code #33453 - Commented with root cause

    • Confirmed JSC GC issue
    • Shared stack traces
  4. WPEWebKit #1622 - Commented with leak evidence

    • Memory leaks (not just crashes)
    • 7,000+ frame stack traces

Pending

WebKit bugs.webkit.org - Requires account creation

  • Report prepared: ISSUE_WEBKIT_GC_LEAKS.md
  • Severity: Critical
  • Component: JavaScriptCore > Garbage Collector

Lessons Learned

Technical

  1. ASAN + Zig = Powerful combination

    • Fast compilation
    • Precise memory control
    • Easy integration with system tools
  2. Classification is key

    • Without it: 100+ "leaks" (mostly false positives)
    • With it: 4 actionable bugs
  3. Symbolication matters

    • Raw PCs: 0x1297C3478 (useless)
    • Symbolicated: JSC::SlotVisitor::drainFromShared (actionable)

Process

  1. Build tools, not just fixes

    • ASAN tracker reusable for ongoing monitoring
    • JSON export for CI integration
  2. Coordinate upstream

    • Single bug → Multiple projects affected
    • Cross-reference all related issues
  3. Document the journey

    • This chronicle helps others reproduce
    • Evidence chain builds credibility

Risk Mitigation

For SOC Health:

  1. Short-term: Use LSAN suppressions for known false positives
  2. Medium-term: Monitor WebKit upstream for GC fixes
  3. Long-term: Upstream fix in JSC parallel GC

Appendix: Full Stack Traces

Leak #1 - HashTable Iterator (Top 30 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
#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)

Leak #2 - Vector Assignment (Top 20 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)

Leak #3 - SlotVisitor (Top 20 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)

Leak #4 - For-Of AST (Top 20 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)

Credits

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.

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.