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.
🌐 阅读中文版本 →On this page
- 1. Forensics on a Stripped Binary
- 2. Two Bugs Compounding Each Other
- 1. Upstream lexmount/moli <= 1.1.28: 1-Second Critical + low_memory_notification() Escalation
- 2. Our sessfork-mcp Lifecycle Blind Spot
- 3. Fixes on Both Sides
- Upstream lexmount/moli v1.1.29
- Hardening sessfork-mcp Without Adding Tokio
- 4. Verified Before / After Benchmarks
- Takeaway for MCP Server Builders
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%(95mcumulative CPU time) - 8 worker threads at
45%–78%each (~72mcumulative 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:
isolate.memory_pressure_notification(v8::MemoryPressureLevel::Critical)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):
-
Zero-Polling Idle Auto-Reaper (Default 300s):
- Moved blocking
stdinline reads onto a lightweight reader thread feeding a boundedstd::sync::mpsc::sync_channel(16)(StdinEvent::Line/Eof). - When no managed
molichild is running,--idle-timeout-secs=0is set, or--cdp-urlattaches to an external browser,next_idle_deadline()returnsNoneand the main loop sleeps inrx.recv()with zero CPU wakeups. - When a managed
moliprocess is active, the main loop sleeps cleanly inrx.recv_timeout(wait)until the exact deadline, then tears down the child process group (reap_if_idle) while preserving the last hot-reloaded"default"storageStatepath so the next tool call wakes up authenticated. - Only successful non-
browser_closetool calls advancelast_activity—IDEinitialize,tools/list, and rejected validation calls never reset the idle timer.
- Moved blocking
-
Closed-Pipe Auto-Recovery & Partial-Init Rollback:
ensure_started()now inspectscdp.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_molisucceeded butopen_tab_in_context("default")orstorageStatehydration returnedErr,self.cdpremainedSome, wedging future calls on"No active tab open". We wrapped initialization with an explicit rollback clearingcdp,contexts,tabs, andlast_activityon error.
-
Fail-Closed Pre-Validation & Dual-Engine Handoff:
browser_set_storage_statenow validates path sandboxing and parses JSON before callingensure_started(), failing closed without spawningmolion invalid inputs.- Updated
SKILL.mdso agents explicitly callsessfork-moli’sbrowser_closewhenever falling back tosessfork-browseror 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:
- Build idle reaping and dead-pipe recovery directly into the server lifecycle;
- Never let protocol housekeeping (
initialize,tools/list, pings) reset your business idle timer; - If you’re running
lexmount/moli, upgrade tov1.1.29or newer.
More Articles (18)
- 中文 当无头浏览器烧满 6 核 CPU:从 567% V8 GC 死循环到零 Tokio Rust MCP 空闲回收
- EN Why Giving an AI Browser MCP Unrestricted File Upload Leaks Your Cookies — And How We Built Fail-Closed Native Uploads in Rust
- 中文 为什么别给 AI 浏览器 MCP 开全盘文件上传:原生 CDP 零拷贝与 4 道 Fail-Closed 防线
- 中文 拆完 14.5K★ GenericAgent 源码后,我把它的 3 个浏览器实战绝招安全搬进了 913 KB 纯 Rust MCP(17/17 对抗测试全绿)
- EN Zero-Dependency Engineering: Adding BibTeX/LaTeX, Git-Diff Gating, SARIF, and Security Confinement to claimcite Without Losing a Millisecond
- 中文 零依赖工程实践:如何在 56ms 冷启动与 0 第三方库约束下,给 claimcite 加上 LaTeX、Git 增量门禁与防注入安全围栏
- 中文 零依赖、可复现地抓出 AI 引文幻觉:从 4 类隐蔽学术造假到本地 xerj:// 字节跨度核验
- EN Catching Silent AI Citation Hallucinations With Zero-Dependency Deterministic Verification
- EN Hardening an AI Browser MCP Without Stripping CSP: Origin-Guarded Iframes, Fail-Fast Batching & 17 Adversarial Probes
- 中文 AI 浏览器 8 步烧掉 174K Token?我把零布局 AXTree 蒸馏塞进 848 KB 纯 Rust MCP,Token 直降 85.4%
- 中文 我用 Rust + Python 拼了一套完全本地、零云端、可逐字验真的 AI Agent 知识库闭环(开源)
- 中文 24 GB 笔记本零 Swap 并发 160 个 AI 浏览器:换纯 Rust MCP 连 Chrome 也省 503 MB
- EN Cutting AI Browser MCP Tokens by 85.4% (174K -> 25K) & Running 160 Parallel Agents with an 848 KB Zero-Tokio Rust Server
- EN Why Qwen3-Reranker-0.6B Hits Only 20.8% Strict Calibration on Financial Traps — And How We Built a Clean-Room 98.3% Fix + 5.4ms ONNX Drop-In
- 中文 砍掉 Node @playwright/mcp 换 605 KB 纯 Rust 管道:Moli 提速 6×、内存降 90.7%(官方 M4 复现)
- 中文 给 19.4k★ Rust AI 搜索引擎 XERJ 做中文 RAG 评测:不改底层代码,如何把 R@3 从 22.2% 拉到 91.1%
- EN Stop AI Agents From Hijacking Your Chrome Window: Fork Live Sessions into Headless Playwright MCP
- 中文 受够 AI 浏览器抢焦点:开源了纯 Python 零依赖工具 sessfork,一键将 Chrome 登录态分叉到无头 Playwright MCP