Skip to content

[MCP]: On stdin EOF the stdio server force-kills its own browser 1 ms after starting the graceful close (Windows) #43098

Closed

Description

@SixFive7

What's going on?

Measured on Windows 11 only. Not tested on macOS or Linux.

When the client closes the stdio server's stdin, two shutdown paths fire:

  1. process.stdin.on('end', () => void transport.close()) in packages/playwright-core/src/tools/utils/mcp/server.ts (line 193 on main), which closes the browser through the normal close.
  2. The exit watchdog, process.stdin.on('close', () => handleExit('close')) in packages/playwright-core/src/tools/mcp/watchdog.ts (line 35 on main), which calls gracefullyCloseAll().

As far as I can read, both reach gracefullyClose() of the same launched browser in packages/utils/processLauncher.ts. The first call sets gracefullyClosing. The second finds it set and takes the force branch (lines 215-219 on main): <forcefully close>, then killProcess(), which on Windows is killProcessTree(), that is taskkill /pid <browser pid> /T /F started through a shell (line 275 on main).

Playwright's own log with DEBUG=pw:browser* shows that. Chromium and Firefox gave the same sequence (2 of 2 runs):

  <gracefully close start>
  <forcefully close>          1 ms later
  <kill>
  <will force kill>
  <process did exit: exitCode=0, signal=null>   about 640 ms (Chromium) and 690 ms (Firefox) after the start
  <gracefully close end>

Tracing the server's child processes: in 8 of 8 runs the server started cmd.exe, which started taskkill.exe, 76 to 106 ms after its stdin was closed.

A persistent profile can lose its latest writes if taskkill lands before the browser's own shutdown has written its stores. Setup: persistent userDataDir; a page writes one persistent cookie (max-age set) and 40 localStorage keys; 1 s later the client closes stdin and the server exits on its own; the same profile is then relaunched and read back.

  • 10 of 12 runs kept everything.
  • 1 of 5 Chromium runs lost the cookie.
  • 1 of 7 Firefox runs lost every localStorage key; the origin's ls/data.sqlite was left at 0 bytes.

Calling browser_close before closing stdin kept everything in 6 of 6 runs (3 Chromium, 3 Firefox), even with the whole process tree killed the moment the tool answered (203 to 286 ms for Chromium, 533 to 592 ms for Firefox).

Steps to reproduce (Windows):

  1. Start the server with a persistent profile, for example a config like
    {"browser": {"browserName": "chromium", "userDataDir": "<an empty folder>",
                 "launchOptions": {"channel": "chrome-for-testing", "headless": true}}}
    and DEBUG=pw:browser* in its environment.
  2. Initialize, then call browser_navigate to a local page that sets a persistent cookie and some localStorage keys.
  3. Wait about 1 s and close the server's stdin.
  4. stderr shows <gracefully close start> followed 1 ms later by <forcefully close> and <will force kill>, and the server starts cmd.exe and taskkill.exe.
  5. Relaunch on the same profile and read the cookie and localStorage. Repeat: the loss shows up in some runs, not all. The same steps with "browserName": "firefox" show the localStorage case.

Expected: on stdin EOF the browser is closed once, gracefully, and force-killed only if that close does not finish (the watchdog already exits after 15 s, and closeOrKill already kills after 30 s).

Possible fixes, untested: let a second gracefullyClose() call wait for the first one instead of killing; or give the stdin-EOF shutdown a single owner (the transport close or the watchdog, not both).

Where the code is (read, not run, unless stated):

  • playwright-core 1.64.0-alpha-1789764292000, pinned by @playwright/mcp 0.0.82 (the measured build): lib/coreBundle.js:9521-9533 (gracefullyClose), 9571-9578 (killProcessTree), 73356 (stdin end), 74118 (stdin close).
  • playwright-core 1.64.0-alpha-1790635538000, pinned by @playwright/mcp 0.0.83: lib/coreBundle.js:9956-9961, 10007, 73936, 74698. Same code.
  • main at c2a031e (2026-10-03): processLauncher.ts:209-221 and 272-275, watchdog.ts:35, server.ts:193. Same code.

Related, not duplicates: #41664 (the stdio server should dispose the browser when stdin closes), #41013 (orphaned Chrome trees when the host dies).

Version

@playwright/mcp 0.0.82 (playwright-core 1.64.0-alpha-1789764292000), Node v24.21.0, Windows 11. Browsers: chromium 1246 (Chrome for Testing 154.0.8037.0) and firefox 1549 (Firefox 156.0), headless.

Activity

  1. github-actions commented on Oct 5, 2026

    @github-actions
    Contributor

    Hi, I'm the Playwright bot and I took a first look on Windows.

    Reproduced with the latest published @playwright/mcp 0.0.83 (playwright-core 1.64.0-alpha-1790635538000). Closing the stdio client starts a graceful browser close and then re-enters the same launcher close path through the stdin close watchdog, which force-kills the browser. This happened with Chromium, Firefox, and WebKit, so the shutdown bug is not browser-specific. The same two stdin handlers and re-entrant force-close branch are still present on current main at a18dade.

    Calling browser_close before closing stdin is an effective control: Chromium then logged one graceful close and no force-kill. This looks like a real bug; #41664 and #41013 cover different lifecycle failures rather than this duplicate shutdown.

    Minimal repro

    I started the MCP CLI with a persistent userDataDir and DEBUG=pw:browser*, connected with the MCP SDK's StdioClientTransport, launched the browser with browser_navigate, and then closed the client:

    const transport = new StdioClientTransport({
      command: process.execPath,
      args: [mcpCLI, '--config', configPath],
      stderr: 'pipe',
      env: { ...process.env, DEBUG: 'pw:browser*' },
    });
    const client = new Client({ name: 'repro', version: '1' });
    await client.connect(transport);
    await client.callTool({
      name: 'browser_navigate',
      arguments: { url: 'data:text/html,<title>repro</title>' },
    });
    await client.close(); // ends the server's stdin

    The config used browserName, a fresh userDataDir, and launchOptions: { headless: true }.

    What I ran

    Windows Server 2025 Datacenter 10.0.26100, Node 24.21.0:

    Browser Build Time from graceful start to force-close Result
    Chromium Chrome for Testing 155.0.8059.12 (v1247) 4 ms <forcefully close>, <will force kill>
    Firefox Firefox 156.0 (v1553) 2 ms <forcefully close>, <will force kill>
    WebKit WebKit 26.6 (v2368) 10 ms <forcefully close>, <will force kill>

    Chromium control with browser_close before stdin EOF:

    <gracefully close start>
    <process did exit: exitCode=0, signal=null>
    <gracefully close end>
    

    I verified the deterministic double-close/force-kill sequence, but did not try to reproduce the reported probabilistic profile data loss in this pass.

    Triaged on Windows by the Playwright bot - agent run

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions