Skip to content

Memory leak on 1.6.0 (no autoConnect): main-isolate old space grows ~13 MiB/min per active session, plateaus when idle, cyclic heap-limit OOMs #2431

Closed

Description

@milordy-coutinho

Environment

  • chrome-devtools-mcp 1.6.0 (global npm install), Node v24.16.0, Debian 13
  • Chrome stable 150.0.7871.186, launched via --executablePath with a persistent --userDataDir, headful on Xvfb
  • One long-lived server process shared by multiple MCP clients through a local stdio proxy; typically 10–30 concurrent MCP sessions
  • Target pages are heavy internal SPAs (dashboards); tools used most: evaluate_script, take_screenshot, navigate_page, take_snapshot
  • --max-old-space-size=1536 on the server process

Symptom

Recurring fatal OOMs of the MCP process under sustained use:

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
... v8::internal::Runtime_AllocateInOldGeneration

Under heavy multi-session activity the process dies roughly every ~3 hours (6 OOMs in a single day at peak usage).

Relationship to #1192

I am aware #1192 was closed as completed. I verified the devtools-frontend fix is present in the 1.6.0 bundle (isPrimaryFrame() in build/src/third_party/index.js has the corrected form). The behavior below persists on 1.6.0, so either this is a different retention path of the same class, or the fix does not cover this usage pattern (no --autoConnect involved).

Instrumentation and data

I injected a sampler into the process via NODE_OPTIONS --import that logs v8.getHeapStatistics() + old_space every 30 s per isolate (main and worker threads tagged separately), plus a per-tool-call log for correlation. Main-isolate old_space over one afternoon cycle (UTC):

time old_space (MiB) note
18:48 27 fresh start
19:18 209 active load
19:48 370 active load
20:18 573 active load
20:48–21:18 ~565 idle period — no growth
21:48 727 load resumes
22:07 1296 +569 MiB in 22 min

Key observations:

  1. Growth is strictly correlated with activity and fully plateaus when idle — consistent with per-event/per-request data being retained, not a timer-based leak.
  2. The final burst (+569 MiB in 22 min) coincided with evaluate_script ×25, take_screenshot ×14, navigate_page ×8 across 2–3 concurrent sessions on heavy SPAs. Normalized, growth is roughly ~13 MiB/min per active session — the same magnitude reported in Memory leak: chrome-devtools-mcp grows ~13 MB/min in --autoConnect mode, causes OOM #1192.
  3. Worker threads (formatter / heap_snapshot / wasmparser from the bundled devtools-frontend) appear in transient bursts (~20 alive for ~40 min under snapshot-heavy load) and are properly terminated — they inflate RSS temporarily but do not explain the main-isolate old_space march.

Question

Is per-target network/event data (or another per-navigation structure) in the bundled devtools-frontend still unbounded on some path exercised by navigation + screenshots + script evaluation? Happy to run additional instrumentation or test patches — this setup reproduces the growth reliably within a few hours of normal agent workload.

Activity

  1. milordy-coutinho commented on Jul 28, 2026

    @milordy-coutinho
    Author

    Additional data point narrowing the mechanism: we captured an OOM where the fatal growth happened with no tool call in flight.

    Timeline (heap sampled every 30 s on the main isolate, --max-old-space-size=1536):

    • 23:52:34 — last tool call of the cycle completes (a 175 ms screenshot)
    • 23:53:55 — old space 906 MiB, stable
    • 23:54:25 — old space 905 MiB, stable
    • 23:54:50 — FATAL ERROR: Reached heap limit — +~440 MiB in ~25 s, more than 2 minutes after the last tool call

    The only activity during that window was background CDP event traffic from open pages (heavy SPAs that poll continuously). So the retention appears to be event-driven, not call-driven: pages left open keep pumping network/console events and something in the bundled devtools-frontend model accumulates them until the isolate hits the heap limit. Tool calls correlate with growth mainly because they open/navigate pages that then generate event traffic.

    This also matches the earlier observation that growth plateaus only when the browser itself is quiet, not merely when the MCP client is idle.

  2. added theissue type on Jul 28, 2026
  3. OrKoN commented on Jul 28, 2026

    @OrKoN
    Collaborator

    Thanks for reporting. @milordy-coutinho do you have a script (using an MCP client for instance) that could help reproduce the memory leak? And to confirm you are not using screencast commands? Note that the MCP server retains network data for up to 3 navigations. If you have really a lot of traffic on a page you might need more memory. The memory should be cleaned if you navigate away or close the page. Do you observe this?

  4. added a commit that references this issue on Jul 31, 2026
    f5282b7
  5. Dmitriusan commented on Aug 3, 2026

    @Dmitriusan
    Contributor

    Reproduced this deterministically and bisected it to a specific line. Short version: the growth is not the network or console collectors, it is the DevTools universe that McpPage creates for every page in the browser.

    Reproduction

    Attach to an already running Chrome that has a realistic set of tabs open (mine had 18: Teams x2, Jira x3, Gmail x2, Telegram, YouTube Music, a few SPAs). Start the server, make exactly one list_pages call, then go completely idle and sample RSS.

    [repro] list_pages done, rss before=142.8MB
    [repro] going idle now -- no further tool calls
    [repro] t=20s rss=2186.0MB
    [repro] t=35s rss=3242.1MB
    [repro] t=50s rss=NaNMB   <- process gone, OOM at the 3 GB cap
    

    That is roughly 100 MB/s with zero tool calls in flight, which matches @milordy-coutinho's observation that the fatal growth happens minutes after the last call. The fatal stack is the giveaway:

    v8::internal::JsonParser<unsigned char>::MakeString(...)
    v8::internal::JsonParser<unsigned char>::ParseJson(...)
    v8::internal::Builtin_JsonParse(...)
    

    The heap is going into parsing inbound CDP messages, so something is subscribed to a very chatty CDP domain across many targets.

    Bisect

    I replicated each step of McpPage's setup separately against the same live browser, 18 pages, 60 s, no tool calls:

    what was done per page RSS over 60 s
    NetworkCollector + ConsoleCollector only (no init()) flat, 140 MB
    page.createCDPSession() only flat, 125 MB
    page.emulateFocusedPage(true) flat, 140 MB
    createTargetUniverse(session) 200 MB -> 1736 MB in 10 s, OOM at the 2 GB cap by ~19 s

    So the collectors are not involved. Worth noting for #2435: the per-navigation request cap is a good change on its own, but it does not touch this. In my run the collectors accumulated 219 requests and 48 console messages in 90 s, nowhere near the 1,000 limit, while RSS was already in gigabytes.

    Root cause

    McpPage.init() calls #initDevToolsUniverseNoThrow() for every page, and createTargetUniverse() does:

    overrideAutoStartModels: new Set([DevTools.DebuggerModel]),

    Force-starting DebuggerModel sends Debugger.enable on the page. The browser then replays every script the page has ever parsed and keeps streaming Debugger.scriptParsed for new ones, and DevTools retains each script. On a script-heavy SPA that is a continuous stream, and it is multiplied by the number of tabs that happen to be open, because createPagesSnapshot() builds an McpPage for all of them.

    The universe is only consumed in two places (McpResponse, to symbolicate stack traces for the page being reported on, and the secondary session for CPU throttling), and devTools: undefined is already a supported input there, since #initDevToolsUniverseNoThrow swallows failures. So the universe does not need to exist for pages nobody is looking at.

    This also explains the shape people reported: it is event driven rather than call driven, it plateaus when the browser is quiet, and the rate varies enormously between users because it depends entirely on how many tabs are open and how much script they parse.

    Fix

    PR: #2463. It creates the universe on demand instead of in init(). selectPage() warms it for the page being worked on, the two consumers await it, and McpPage.dispose() detaches its CDP session so closed tabs stop being tracked. That turns N universes into 1.

    Both reproduction scripts are in the PR description if you want to run them yourselves.

  6. OrKoN commented on Aug 3, 2026

    @OrKoN
    Collaborator
  7. OrKoN commented on Aug 3, 2026

    @OrKoN
    Collaborator

    @Dmitriusan did you dive into what is it that causes the leak within the DevToolsUniverse instances? I would expect the memory usage to also remain stable with DevTools Universe being on.

  8. Dmitriusan commented on Aug 3, 2026

    @Dmitriusan
    Contributor

    Hi @OrKoN,

    Dug into your question, and I've updated #2463 with a different approach based on the answer.

    Short version: it is automatic source map loading, and it is not really a leak. It is a large, retained, one-off cost per page. Your expectation holds for most pages and breaks on pages that ship source maps.

    What it is

    DebuggerModel.parsedScriptSource() calls attachSourceMap() for every script carrying a sourceMapURL, since SourceMapManager defaults to enabled and nothing turns it off. Each map is downloaded, VLQ decoded, sorted, reverse mapped, and the decoded mappings stay alive as long as the model does.

    One Jira issue page, one universe, forcing a full GC every second so this is retention and not GC lag:

    t= 2s  heap  491 ->  314 MB after full GC
    t=12s  heap 2205 -> 1950 MB
    t=19s  heap 2427 -> 2426 MB   <- plateau
    t=40s  heap 2427 -> 2427 MB   <- still flat
    

    2427 MB, then flat forever. Adding one line right after createTargetUniverse():

    universe.target.model(DevTools.DebuggerModel).sourceMapManager().setEnabled(false)

    gives 59 MB instead. Everything else identical.

    Supporting evidence: 147 of the 147 Network.loadNetworkResource calls the universe made in 8 seconds were .map files, plus 561 IO.read calls streaming them back; the CPU profile of the growth window is dominated by parseSourceMap, #computeReverseMappings and nextVLQ.

    That plateau is the "plateaus when idle" from the original report. Growth stops once the page runs out of new scripts. And the wildly different rates people report are just whether the app ships source maps: on the same browser, Jira 2.4 GB retained, Azure DevOps roughly zero, Teams and Gmail flat. The multiplier is createPagesSnapshot() building an McpPage for every page in the browser, so that bill is paid per open tab.

    The updated PR

    #2463 now leaves universe creation alone. The universe only needs source maps to symbolicate the frames of a stack trace it is about to format, and createStackTrace() already walks exactly those scripts, so the PR refuses developer resource loads by default and attaches the map for one script when it is needed.

    It is tested and works in the case that was failing on my machine: my daily browser with 18 ordinary tabs open, where main goes to 4.9 GB and OOMs within a minute of a single list_pages call. On the branch it settles at 210 MB and stays there, with all 18 pages still getting a universe. Stack traces come out byte for byte identical against a fixture with a real source map, and get_console_message on a 2.8 MB map got faster rather than slower (1893/1882/2340 ms -> 133/139/142 ms, three runs each). No new test failures.

    Two traps, in case they save someone time. Blocking the CDP Network.loadNetworkResource command alone changes nothing, because PageResourceLoader.dispatchLoad() falls back to loadFromHostBindings(), so the download just reroutes. And SourceMapManager.setEnabled(false) cannot be toggled around a symbolication, because setEnabled(true) re-attaches every registered client at once.

    Separately, the uncaught Unknown session crash I mentioned is now #2466 with a regression test. Unrelated to this, I just kept hitting it while measuring.

  9. added a commit that references this issue on Aug 3, 2026
    8b44a31
  10. yulunz commented on Aug 4, 2026

    @yulunz
    Collaborator

    Verified source maps served from Jira is bloating the memory because of eager loading, as @Dmitriusan had pointed out. To fix this
    we are adding a feature to lazy load the source map in the upstream (link), and I will update the MCP server once that's reflected here.

    Separately, there are other sources of memory leak: 1) not properly disposing IsolatedFileSystemManager, and 2) not unregistering handlers in PuppeteerDevToolsConnection. #2465 attempts to fix both but we will abandon that and fill fix those in the upstream instead (link, and more coming).

    It seems there are multiple instances of memory leaks / unexpected increase in memory already. We will update the regression tests in scripts/eval_scenarios to be able to better prevent / catch instances like this in the future.

    Thanks to everyone who contributed debugging this issue! Please keep the reports coming if you all see anything :)

  11. OrKoN commented on Aug 10, 2026

    @OrKoN
    Collaborator

    This should be fixed in 1.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions