← Back to all articles

When a Headless Browser Burns 6 Cores: Debugging a 567% V8 GC Spin and Building a Zero-Tokio MCP Idle Reaper

How we traced a 567% CPU runaway on macOS via /usr/bin/sample and stripped-binary disassembly to a V8 Major GC death spiral in moli 1.1.27, verified the upstream v1.1.29 fix on live heavy SPAs, and hardened sessfork-mcp with zero-polling idle reaping and closed-pipe auto-recovery.

🌐 阅读中文版本 →
#Rust#MCP#V8#Performance#Browser Automation
On this page

This afternoon, my 10-core Apple Silicon Mac suddenly turned into a space heater. System load average hit 27.80, and Activity Monitor showed a single headless browser process (moli 1.1.27) pinned at 214.5%–566.9% CPU—burning 11 hours and 12 minutes of CPU time in just 2 hours and 24 minutes of wall time, while holding 1.31 GB of memory (1.4 GB peak).

At first glance, it looked like a rogue requestAnimationFrame or setInterval loop on a webpage. A deeper dive with /usr/bin/sample and binary disassembly uncovered something much more instructive: a textbook collision between an upstream V8 GC death spiral and an MCP lifecycle blind spot.

This post walks through the exact forensic trail, why both bugs had to collide to cook the machine, and how we fixed our side in sessfork-mcp (our zero-Node.js, zero-Tokio Rust CDP MCP server; commit d6882a4).


1. Forensics on a Stripped Binary

Checking per-thread CPU accounting via ps -M immediately ruled out a single-threaded JavaScript loop. Nine threads were spinning simultaneously:

  • 1 V8 isolate thread at 88.8% (95m cumulative CPU time)
  • 8 worker threads at 45%–78% each (~72m cumulative CPU time apiece)

A 1-second /usr/bin/sample capture showed the 8 threads belonged to V8 DefaultWorkerThreadsTaskRunner WorkerThread, all jammed inside two stripped offsets (0x1023fc244 and 0x102504f20 after subtracting the ASLR slide).

Without debug symbols, I wrote a quick Python helper to scan ARM64 ADRP + ADD instruction pairs around those hot addresses and resolve the referenced C strings in __TEXT:

  • Near 0x1023fc244: ConcurrentMarkerMajorBgThread, !IsFreeSpaceOrFillerMap(map), Worklist::Segment::Create
  • Near 0x102504f20: MajorSweeperBgThread, Sweeper::SweepingState<Major>::StartConcurrentSweeping()

Six CPU cores were not running webpage JavaScript at all—they were trapped in nonstop V8 Major GC concurrent marking and sweeping.


2. Two Bugs Compounding Each Other

V8 does not burn 9 threads on an idle page by itself. Correlating the thread trace against session history and upstream source revealed two bugs colliding:

1. Upstream lexmount/moli <= 1.1.28: 1-Second Critical + low_memory_notification() Escalation

In moli 1.1.27 (moli-renderer-v8’s owner_maintenance.rs and runtime_observability.rs), a periodic maintenance task fired every 1 second for every live page and checked whether used_heap_size >= heap_size_limit / 3. When crossed, it invoked both:

  1. isolate.memory_pressure_notification(v8::MemoryPressureLevel::Critical)
  2. isolate.low_memory_notification()

When a tab holds a heavy collaborative-document SPA (with a large live block tree, editor state, and closures), its reachable heap stays above heap_size_limit / 3 regardless of how aggressively GC runs. Because each low_memory_notification() runs full Mark-Compact Major GCs across the isolate and its 8 worker threads (~1 second of wall time), the next 1-second timer fired immediately after—locking 9 threads into an infinite ~567% CPU spin loop.

2. Our sessfork-mcp Lifecycle Blind Spot

Why was an abandoned document tab still open 2.4 hours later?

Earlier that day, an AI agent had opened several heavy collaborative-doc pages with zero-layout sessfork-moli, discovered virtualized scrolling needed full layout, and automatically fell back to headless Chromium (sessfork-browser)—without calling browser_close() on sessfork-moli.

Because IDE stdio MCP servers stay alive for hours blocked on stdin.lock().lines(), that orphaned tab kept cooking silently in the background. Worse, ensure_started() only checked self.cdp.is_some() without checking cdp.is_closed(), meaning if a child moli process ever died or was killed externally, the MCP server stayed permanently wedged returning "CDP pipe is closed".


3. Fixes on Both Sides

Upstream lexmount/moli v1.1.29

Checking lexmount/moli, the maintainers had already tracked the idle GC issue in #3791 and shipped PR #3891 in v1.1.29 on 2026-12-01—removing the 1-second timer, the heap_size_limit / 3 escalation, and low_memory_notification(), and replacing them with IsolateMemoryPressure (3s sampling, sending Moderate only on > 7 MiB growth or a 17s fallback interval).

Hardening sessfork-mcp Without Adding Tokio

sessfork-mcp intentionally compiles with zero Tokio and zero async runtime (~950 KB single binary). To add an idle reaper without introducing a background polling loop or async dependencies, we built three defenses in pure std Rust (d6882a4):

  1. Zero-Polling Idle Auto-Reaper (Default 300s):

    • Moved blocking stdin line reads onto a lightweight reader thread feeding a bounded std::sync::mpsc::sync_channel(16) (StdinEvent::Line / Eof).
    • When no managed moli child is running, --idle-timeout-secs=0 is set, or --cdp-url attaches to an external browser, next_idle_deadline() returns None and the main loop sleeps in rx.recv() with zero CPU wakeups.
    • When a managed moli process is active, the main loop sleeps cleanly in rx.recv_timeout(wait) until the exact deadline, then tears down the child process group (reap_if_idle) while preserving the last hot-reloaded "default" storageState path so the next tool call wakes up authenticated.
    • Only successful non-browser_close tool calls advance last_activity—IDE initialize, tools/list, and rejected validation calls never reset the idle timer.
  2. Closed-Pipe Auto-Recovery & Partial-Init Rollback:

    • ensure_started() now inspects cdp.is_closed(), clears stale handles when the child process dies, and respawns cleanly on the next call.
    • An independent adversarial diff review also caught a P1 partial-init bug: if spawn_moli succeeded but open_tab_in_context("default") or storageState hydration returned Err, self.cdp remained Some, wedging future calls on "No active tab open". We wrapped initialization with an explicit rollback clearing cdp, contexts, tabs, and last_activity on error.
  3. Fail-Closed Pre-Validation & Dual-Engine Handoff:

    • browser_set_storage_state now validates path sandboxing and parses JSON before calling ensure_started(), failing closed without spawning moli on invalid inputs.
    • Updated SKILL.md so agents explicitly call sessfork-moli’s browser_close whenever falling back to sessfork-browser or finishing a heavy SPA, pairing immediate release with the 5-minute server-side safety net.

4. Verified Before / After Benchmarks

After upgrading to moli 1.1.29 and rebuilding sessfork-mcp 0.3.2, we ran two empirical checks:

Workload Before (moli 1.1.27) After (moli 1.1.29 + sessfork-mcp)
Synthetic stress: 2.5M live V8 JS objects (~369 MB RSS), 22s idle — 2.82% avg CPU (0.95s total CPU over 22s; 0.0% between ticks)
Exact real-world replay: 7 sequential navigations across 4 heavy collaborative-doc SPAs + scroll eval, 42s idle 214.5%–566.9% CPU (11h 12m in 2.4h), 1.31 GB footprint 0.0%–2.1% CPU (+1.12s total CPU across 42s), MEM flat at 691–697 MB, RSS dropping 809 MB → 757 MB
Engineering gates — cargo fmt, cargo clippy --all-targets --all-features -- -D warnings (0 warnings), 53/53 Rust unit tests, 53/53 Python + live E2E tests (covering SIGKILL recovery, tools/list non-reset, 2s idle reaping, and --cdp-url non-reap negative control)

Takeaway for MCP Server Builders

Never rely on an LLM to remember browser_close().

If your stdio MCP server spawns stateful child processes:

  1. Build idle reaping and dead-pipe recovery directly into the server lifecycle;
  2. Never let protocol housekeeping (initialize, tools/list, pings) reset your business idle timer;
  3. If you’re running lexmount/moli, upgrade to v1.1.29 or newer.
Discussion & Feedback Join the discussion or share feedback on GitHub Discussions →