Skip to content

macOS: every session leaks a ~1.4 GB Chrome code_sign_clone because Chrome is SIGKILLed on shutdown #3154

Description

@bezlant

Environment: chrome-devtools-mcp 1.10.1, Google Chrome 155.0.8059.40 (stable), macOS 27.0, Apple Silicon. Client: Codex CLI 0.162.1.

What happens

Since Chrome ~121, Chrome copies its app bundle into $(getconf DARWIN_USER_DIR)/../X/com.google.Chrome.code_sign_clone/code_sign_clone.XXXXXX at launch, and deletes the copy only on a graceful shutdown. When an MCP client ends a session by signalling the server, Chrome is killed before it can clean up, so the copy stays. I had 53 leftover copies, reported as 74 GB (they share APFS blocks, but each new Chrome version costs another ~1.4 GB).

Cause

The bundled @puppeteer/browsers handles SIGTERM/SIGHUP with close() → kill(), which sends process.kill(-pid, 'SIGKILL') to Chrome's whole process group (packages/browsers/src/launch.ts, still present in v3.2.5). SIGINT calls kill() directly. None of these paths sends Browser.close over CDP first.

Repro

Count code_sign_clone.* dirs before and after each session:

How the session ended Leaked
MCP sent SIGTERM 3/3
MCP sent SIGINT 1/1
MCP sent SIGKILL 1/2
Real codex exec session using new_page 2/2
stdin closed (server calls browser.close()) 0/2
Same Codex session with --executablePath → Chrome for Testing 0/2

Chrome itself also leaks the copy on a plain SIGTERM or SIGKILL sent directly to it, so only a CDP Browser.close avoids the leak.

Suggested fix

On SIGTERM/SIGINT/SIGHUP, try browser.close() (CDP) with a short timeout before falling back to the process-group SIGKILL. Alternatively, document --executablePath pointing at Chrome for Testing as the workaround on macOS, since Chrome for Testing doesn't create these copies.

Workaround

--executablePath=<path to Google Chrome for Testing>

Activity

  1. OrKoN commented on Oct 15, 2026

    @OrKoN
    Collaborator

    On SIGTERM/SIGINT/SIGHUP, try browser.close() (CDP) with a short timeout before falling back to the process-group SIGKILL. Alternatively, document --executablePath pointing at Chrome for Testing as the workaround on macOS, since Chrome for Testing doesn't create these copies.

    this is how the browser is closed in the latest version which sounds like the suggested fix:

    async #closeLaunchedBrowser(browser: Browser): Promise<void> {
        let timer: ReturnType<typeof setTimeout> | undefined;
        try {
          await Promise.race([
            browser.close(),
            new Promise<never>((_, reject) => {
              timer = setTimeout(
                () => reject(new Error('Timed out closing browser')),
                5_000,
              );
              timer.unref?.();
            }),
          ]);
        } catch (err) {
          logger?.('Failed to close browser', err);
          browser.process()?.kill('SIGKILL');
        } finally {
          clearTimeout(timer);
        }
      }
    

    can you provide a scripted reproduction to avoid ambiguities?

  2. added theissue type on Oct 15, 2026
  3. bezlant commented on Oct 15, 2026

    @bezlant
    Author

    Thanks! I re-tested on 1.11.0 with a scripted repro. The graceful browser.close() path is there, but it loses a race: BrowserManager calls puppeteer.launch() without handleSIGINT/handleSIGTERM/handleSIGHUP: false, so Puppeteer's own signal handler also fires on the same signal and synchronously runs process.kill(-pid, 'SIGKILL') on Chrome's process group before shutdown() → browser.close() completes. Chrome only deletes its code_sign_clone on a graceful close, so it leaks.

    Results (stable Chrome 155, macOS 27, Apple Silicon):

    Signal 1.11.0 1.11.0 + handleSIGINT/SIGTERM/SIGHUP: false in puppeteer.launch()
    SIGTERM leaked (2/2) clean (2/2)
    SIGINT leaked clean
    SIGHUP leaked clean
    stdin close clean —

    Suggested fix: pass handleSIGINT: false, handleSIGTERM: false, handleSIGHUP: false to puppeteer.launch() in BrowserManager.js, since chrome-devtools-mcp-main.js already handles those signals itself.

    Repro: npm i chrome-devtools-mcp@latest && node repro.mjs SIGTERM (prints LEAKED or clean; exit code 1 on leak).

    repro.mjs
    // Repro for ChromeDevTools/chrome-devtools-mcp#3154 (macOS only).
    // Launches the MCP server over stdio, makes it start Chrome, sends a signal,
    // then counts Chrome code_sign_clone directories left behind.
    //
    //   npm i chrome-devtools-mcp@latest
    //   node repro.mjs [SIGTERM|SIGINT|SIGHUP|stdin]   (default SIGTERM)
    //   MCP_BIN=/path/to/build/src/bin/chrome-devtools-mcp.js node repro.mjs
    //
    // Uses stable Chrome (the default channel); Chrome for Testing makes no clone.
    import {spawn, execFileSync} from 'node:child_process';
    import {readdirSync, existsSync} from 'node:fs';
    import {dirname, join} from 'node:path';
    import {setTimeout as sleep} from 'node:timers/promises';
    import {createInterface} from 'node:readline';
    import {createRequire} from 'node:module';
    
    const mode = process.argv[2] ?? 'SIGTERM';
    const tempDir = execFileSync('getconf', ['DARWIN_USER_TEMP_DIR']).toString().trim();
    const cloneDir = join(dirname(tempDir), 'X', 'com.google.Chrome.code_sign_clone');
    const clones = () =>
      existsSync(cloneDir) ? readdirSync(cloneDir).filter(d => d.startsWith('code_sign_clone.')).length : 0;
    
    // Run node directly (not via npx) so the signal reaches the server process itself.
    const bin = process.env.MCP_BIN ??
      createRequire(import.meta.url).resolve('chrome-devtools-mcp/package.json')
        .replace(/package\.json$/, 'build/src/bin/chrome-devtools-mcp.js');
    
    const before = clones();
    const server = spawn('node', [bin, '--isolated', '--no-usage-statistics'], {stdio: ['pipe', 'pipe', 'inherit']});
    const lines = createInterface({input: server.stdout});
    const pending = new Map();
    lines.on('line', l => {
      const msg = JSON.parse(l);
      pending.get(msg.id)?.(msg);
    });
    let nextId = 1;
    const rpc = (method, params) =>
      new Promise(resolve => {
        const id = nextId++;
        pending.set(id, resolve);
        server.stdin.write(JSON.stringify({jsonrpc: '2.0', id, method, params}) + '\n');
      });
    
    await rpc('initialize', {protocolVersion: '2025-06-18', capabilities: {}, clientInfo: {name: 'repro', version: '0'}});
    server.stdin.write(JSON.stringify({jsonrpc: '2.0', method: 'notifications/initialized'}) + '\n');
    await rpc('tools/call', {name: 'list_pages', arguments: {}});
    const during = clones();
    
    const exited = new Promise(resolve => server.on('exit', resolve));
    if (mode === 'stdin') server.stdin.end();
    else server.kill(mode);
    await exited;
    await sleep(8000); // give Chrome time to delete its clone on a graceful exit
    
    const after = clones();
    console.log(`${mode}: before=${before} during=${during} after=${after} -> ${after > before ? 'LEAKED' : 'clean'}`);
    process.exit(after > before ? 1 : 0);
  4. self-assigned this
    on Oct 15, 2026
  5. removed their assignment
    on Oct 15, 2026
  6. OrKoN commented on Oct 16, 2026

    @OrKoN
    Collaborator

    I am not able to reproduce:

    ❯ node repro.mjs
    chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
    debug, and modify any data in the browser or DevTools.
    Avoid sharing sensitive or personal information that you do not want to share with MCP clients.
    Performance tools may send trace URLs to the Google CrUX API to fetch real-user experience data. To disable, run with --no-performance-crux.
    SIGTERM: before=1 during=1 after=1 -> clean
    
    ~/src/chrome-devtools-mcp main 13s
    ❯ node repro.mjs
    chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
    debug, and modify any data in the browser or DevTools.
    Avoid sharing sensitive or personal information that you do not want to share with MCP clients.
    Performance tools may send trace URLs to the Google CrUX API to fetch real-user experience data. To disable, run with --no-performance-crux.
    SIGTERM: before=1 during=1 after=1 -> clean
    
    ~/src/chrome-devtools-mcp main 8s
    ❯ node repro.mjs
    chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
    debug, and modify any data in the browser or DevTools.
    Avoid sharing sensitive or personal information that you do not want to share with MCP clients.
    Performance tools may send trace URLs to the Google CrUX API to fetch real-user experience data. To disable, run with --no-performance-crux.
    SIGTERM: before=1 during=1 after=1 -> clean
    

    As far as I know Puppeteer also first tries graceful close before killing the hanging browser.

  7. bezlant commented on Oct 16, 2026

    @bezlant
    Author

    Thanks for running it! In your output during equals before (1 → 1), so Chrome never created a code-sign clone, which means that run can't show the leak. Per Chromium's code_sign_clone_manager.mm, kMacAppCodeSignClone is enabled by default but compiled out for Chrome for Testing, and the clone is only removed from ~CodeSignCloneManager during a graceful shutdown. A SIGKILL skips it, and /var/folders/…/X is only wiped at reboot, so leaks pile up over uptime (53 after 12 days here). Could you check whether the launched Chrome is Chrome for Testing or a non-stable build? The updated repro below prints the executable path and reports INCONCLUSIVE when no clone is created.

    On my machine (stable Chrome 155.0.8059.84 from /Applications, macOS 27.0.1): before=6 during=7 after=7 → LEAKED. For SIGTERM/SIGHUP, @puppeteer/browsers calls close(), which goes straight to kill() and sends process.kill(-pid, 'SIGKILL') (launch.ts L436–450, L492). There's no CDP Browser.close on that path. Passing handleSIGTERM/SIGINT/SIGHUP: false to puppeteer.launch() lets the MCP's own shutdown() → browser.close() run, and then the clone is cleaned up (4/4 here).

    repro.mjs (updated)
    // Repro for ChromeDevTools/chrome-devtools-mcp#3154 (macOS only).
    // Launches the MCP server over stdio, makes it start Chrome, sends a signal,
    // then counts Chrome code_sign_clone directories left behind.
    //
    //   npm i chrome-devtools-mcp@latest
    //   node repro.mjs [SIGTERM|SIGINT|SIGHUP|stdin]   (default SIGTERM)
    //   MCP_BIN=/path/to/build/src/bin/chrome-devtools-mcp.js node repro.mjs
    //
    // Uses stable Chrome (the default channel); Chrome for Testing makes no clone.
    import {spawn, execFileSync} from 'node:child_process';
    import {readdirSync, existsSync} from 'node:fs';
    import {dirname, join} from 'node:path';
    import {setTimeout as sleep} from 'node:timers/promises';
    import {createInterface} from 'node:readline';
    import {createRequire} from 'node:module';
    
    const mode = process.argv[2] ?? 'SIGTERM';
    const tempDir = execFileSync('getconf', ['DARWIN_USER_TEMP_DIR']).toString().trim();
    const cloneDir = join(dirname(tempDir), 'X', 'com.google.Chrome.code_sign_clone');
    const clones = () =>
      existsSync(cloneDir) ? readdirSync(cloneDir).filter(d => d.startsWith('code_sign_clone.')).length : 0;
    
    // Run node directly (not via npx) so the signal reaches the server process itself.
    const bin = process.env.MCP_BIN ??
      createRequire(import.meta.url).resolve('chrome-devtools-mcp/package.json')
        .replace(/package\.json$/, 'build/src/bin/chrome-devtools-mcp.js');
    
    const before = clones();
    const server = spawn('node', [bin, '--isolated', '--no-usage-statistics'], {stdio: ['pipe', 'pipe', 'inherit']});
    const lines = createInterface({input: server.stdout});
    const pending = new Map();
    lines.on('line', l => {
      const msg = JSON.parse(l);
      pending.get(msg.id)?.(msg);
    });
    let nextId = 1;
    const rpc = (method, params) =>
      new Promise(resolve => {
        const id = nextId++;
        pending.set(id, resolve);
        server.stdin.write(JSON.stringify({jsonrpc: '2.0', id, method, params}) + '\n');
      });
    
    await rpc('initialize', {protocolVersion: '2025-06-18', capabilities: {}, clientInfo: {name: 'repro', version: '0'}});
    server.stdin.write(JSON.stringify({jsonrpc: '2.0', method: 'notifications/initialized'}) + '\n');
    await rpc('tools/call', {name: 'list_pages', arguments: {}});
    const during = clones();
    const chromePath = execFileSync('sh', ['-c', `ps -axo pid=,ppid=,command= | awk '$2==${server.pid}' | grep -v crashpad | sed -E 's/^ *[0-9]+ +[0-9]+ +//; s/ --.*//' | head -1`]).toString().trim();
    
    const exited = new Promise(resolve => server.on('exit', resolve));
    if (mode === 'stdin') server.stdin.end();
    else server.kill(mode);
    await exited;
    await sleep(8000); // give Chrome time to delete its clone on a graceful exit
    
    const after = clones();
    console.log(`chrome launched from: ${chromePath || 'unknown'}`);
    if (during <= before) {
      // Chrome only clones itself on macOS 14+ stable/beta builds; no clone means nothing to leak.
      console.log(`${mode}: before=${before} during=${during} after=${after} -> INCONCLUSIVE (Chrome made no code_sign_clone)`);
      process.exit(2);
    }
    console.log(`${mode}: before=${before} during=${during} after=${after} -> ${after > before ? 'LEAKED' : 'clean'}`);
    process.exit(after > before ? 1 : 0);
  8. bezlant commented on Oct 16, 2026

    @bezlant
    Author

    Quick correction and an update after an independent re-test (separate agent, fresh install, Node 22 + 24, tracking the clone directory names rather than counts):

    • Scope, narrowed: the leak happens when the MCP server is stopped by a signal (SIGTERM/SIGINT/SIGHUP) after Chrome has launched and created a clone. A normal stdin-close shutdown cleans up fine, so "every session" in my first post was too broad. Also, sending SIGINT or SIGHUP directly to Chrome cleans up; only a direct SIGTERM leaks, because it goes through SessionEnding(), which exits immediately.
    • Root cause, unchanged: Puppeteer's default handleSIGTERM/SIGINT/SIGHUP SIGKILLs Chrome's process group before the MCP's own shutdown() → browser.close() finishes. SIGTERM shutdown completed in 33–50 ms, so the 5 s timeout isn't involved. Leaked clones were still present after ~6 min; clean runs remove them in ~0.3 s. With the three options set to false in puppeteer.launch(), SIGTERM/SIGINT/SIGHUP were all clean.
    • Repro fix: the earlier script printed counts even if list_pages failed (Chrome never launched), which would also produce before=1 during=1 after=1. It now exits with code 3 and prints the error in that case. Exit codes: 0 = clean, 1 = leaked, 2 = inconclusive (no clone created), 3 = tool call failed.

    Could you re-run the updated script (below) and share its output, including the chrome launched from: line?

    repro.mjs (updated)
    // Repro for ChromeDevTools/chrome-devtools-mcp#3154 (macOS only).
    // Launches the MCP server over stdio, makes it start Chrome, sends a signal,
    // then counts Chrome code_sign_clone directories left behind.
    //
    //   npm i chrome-devtools-mcp@latest
    //   node repro.mjs [SIGTERM|SIGINT|SIGHUP|stdin]   (default SIGTERM)
    //   MCP_BIN=/path/to/build/src/bin/chrome-devtools-mcp.js node repro.mjs
    //
    // Uses stable Chrome (the default channel); Chrome for Testing makes no clone.
    import {spawn, execFileSync} from 'node:child_process';
    import {readdirSync, existsSync} from 'node:fs';
    import {dirname, join} from 'node:path';
    import {setTimeout as sleep} from 'node:timers/promises';
    import {createInterface} from 'node:readline';
    import {createRequire} from 'node:module';
    
    const mode = process.argv[2] ?? 'SIGTERM';
    const tempDir = execFileSync('getconf', ['DARWIN_USER_TEMP_DIR']).toString().trim();
    const cloneDir = join(dirname(tempDir), 'X', 'com.google.Chrome.code_sign_clone');
    const clones = () =>
      existsSync(cloneDir) ? readdirSync(cloneDir).filter(d => d.startsWith('code_sign_clone.')).length : 0;
    
    // Run node directly (not via npx) so the signal reaches the server process itself.
    const bin = process.env.MCP_BIN ??
      createRequire(import.meta.url).resolve('chrome-devtools-mcp/package.json')
        .replace(/package\.json$/, 'build/src/bin/chrome-devtools-mcp.js');
    
    const before = clones();
    const server = spawn('node', [bin, '--isolated', '--no-usage-statistics'], {stdio: ['pipe', 'pipe', 'inherit']});
    const lines = createInterface({input: server.stdout});
    const pending = new Map();
    lines.on('line', l => {
      const msg = JSON.parse(l);
      pending.get(msg.id)?.(msg);
    });
    let nextId = 1;
    const rpc = (method, params) =>
      new Promise(resolve => {
        const id = nextId++;
        pending.set(id, resolve);
        server.stdin.write(JSON.stringify({jsonrpc: '2.0', id, method, params}) + '\n');
      });
    
    await rpc('initialize', {protocolVersion: '2025-06-18', capabilities: {}, clientInfo: {name: 'repro', version: '0'}});
    server.stdin.write(JSON.stringify({jsonrpc: '2.0', method: 'notifications/initialized'}) + '\n');
    const call = await rpc('tools/call', {name: 'list_pages', arguments: {}});
    if (call.error || call.result?.isError) {
      // Chrome never launched, so the clone counts below would mean nothing.
      console.log(`list_pages failed: ${JSON.stringify(call.error ?? call.result.content)}`);
      server.kill('SIGKILL');
      process.exit(3);
    }
    const during = clones();
    const chromePath = execFileSync('sh', ['-c', `ps -axo pid=,ppid=,command= | awk '$2==${server.pid}' | grep -v crashpad | sed -E 's/^ *[0-9]+ +[0-9]+ +//; s/ --.*//' | head -1`]).toString().trim();
    
    const exited = new Promise(resolve => server.on('exit', resolve));
    if (mode === 'stdin') server.stdin.end();
    else server.kill(mode);
    await exited;
    await sleep(8000); // give Chrome time to delete its clone on a graceful exit
    
    const after = clones();
    console.log(`chrome launched from: ${chromePath || 'unknown'}`);
    if (during <= before) {
      // Chrome only clones itself on macOS 14+ stable/beta builds; no clone means nothing to leak.
      console.log(`${mode}: before=${before} during=${during} after=${after} -> INCONCLUSIVE (Chrome made no code_sign_clone)`);
      process.exit(2);
    }
    console.log(`${mode}: before=${before} during=${during} after=${after} -> ${after > before ? 'LEAKED' : 'clean'}`);
    process.exit(after > before ? 1 : 0);
  9. OrKoN commented on Oct 17, 2026

    @OrKoN
    Collaborator

    @bezlant I will check but closing a stdio server this way is not according to the spec https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/stdio#shutdown what is the reason for not closing the stdio and shutting down via the signal instead?

  10. bezlant commented on Oct 17, 2026

    @bezlant
    Author

    Fair point, thanks. I checked what my client actually does. Logging the MCP's stdin and signals during a real Codex CLI 0.162.1 session shows Codex sends SIGTERM first and closes stdin ~40 ms later, which is the reverse of the spec's order. So the trigger is my client, and a spec-compliant client wouldn't hit this. I've reported it to Codex on their existing shutdown issue: openai/codex#48524 (comment)

    I'd still suggest the one-line change as hardening: the server already registers SIGTERM/SIGINT/SIGHUP handlers that run a graceful browser.close(), but Puppeteer's default handlers SIGKILL Chrome first, so those handlers can't do their job. SIGTERM is also the spec's escalation step, and Ctrl+C on a terminal-launched client delivers SIGINT to the whole process group. Passing handleSIGINT/SIGTERM/SIGHUP: false to puppeteer.launch() makes the existing handlers work as intended. Totally fine if you'd rather close this as a client issue.

  11. OrKoN commented on Oct 17, 2026

    @OrKoN
    Collaborator

    @bezlant I will check next week: just want to avoid a whac-a-mole game in case not handling signals would result in additional regressions like hanging or leaking Chrome in some situations.

  12. self-assigned this
    on Oct 17, 2026
  13. added a commit that references this issue on Oct 19, 2026
    3afec73
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