Repository navigation
fix(mcp): close the browser once when the client disconnects - #43139
Pavel Feldman (pavelfeldman) wants to merge 1 commit into
Conversation
On stdin end, the MCP server closed its transport, and the exit watchdog closed the browsers at the same time. Whichever path came second force-killed the browser. Remove the 'end' handler, so the watchdog is the only shutdown path. Processes that must exit when their parent dies listen for 'close' on stdin. Node only emits it once stdin has been read to the end, so most of these listeners never fired. Add onParentProcessExit(), which reads stdin and skips terminals, and use it in all such processes. Fixes: microsoft#43098
Test results for "tests 1"7 flaky52653 passed, 1270 skipped Merge workflow run. |
Test results for "MCP"2 failed 9059 passed, 1495 skipped Merge workflow run. |
|
Hi, I'm the Playwright bot and I took a first look at the CI failures. 🟢 Both failures are pre-existing flakes — this PR is clearThe two Windows/Firefox failures have the same test identities and error signatures on unrelated SHAs. This PR's shutdown changes activate when stdin closes; these failures happened during active client calls, and the new disconnect/shutdown tests passed. DetailsOverall: the MCP report has 2 failures, both confirmed pre-existing flakes. The separate Pre-existing flake / infra
Triaged by the Playwright bot - agent run |
Summary
'end'handler so the watchdog is the only shutdown path.'close'without reading stdin, so the event never fired. AddonParentProcessExit(), which reads stdin and skips terminals, and use it in the MCP watchdog,run-server, the test server, the trace viewer, and the dashboard app.Scenarios where self-destruction did not work
Node emits
'close'onprocess.stdinonly after stdin has been read to the end. These processes attached a'close'listener, but nothing read stdin, so they never noticed that the parent had exited:run-mcp-server --port,run-test-mcp-server --portrun-servertest-server(VS Code extension),--uidashboardApp.js --annotate)browser_annotate'end'handler killed it through the abort signalplaywright-cli show, before it reports readyAlready working:
run-mcp-serverin stdio mode (the SDK transport reads stdin) and the trace viewer in--stdinmode (it reads trace URLs). Not affected: the CLI daemon and the dashboard daemon started bybrowser_annotateget/dev/nullas stdin. It never emits'close', and both are meant to outlive their parent.Fixes #43098