fix(browser): dispose CDP listeners when tester disconnects (fix #10810) - #10884
Open
alohasick wants to merge 1 commit into
Open
fix(browser): dispose CDP listeners when tester disconnects (fix #10810)#10884alohasick wants to merge 1 commit into
alohasick wants to merge 1 commit into
Conversation
sheremet-va
requested changes
Aug 11, 2026
|
|
||
| const { stderr, testTree } = await runInlineBrowserTests( | ||
| { | ||
| 'a.test.ts': ` |
Member
There was a problem hiding this comment.
Why would either of the tests here fail without the fix?
| @@ -0,0 +1,68 @@ | |||
| import type { CDPSession } from 'vitest/node' | |||
Member
There was a problem hiding this comment.
These tests don't test anything, everything is mocked
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a crash in browser mode where stale CDP event listeners cause the entire test run to abort mid-way.
Root cause:
removeCDPHandler()inpackages/browser/src/node/projectParent.tsonly deleted theBrowserServerCDPHandlerfrom its internal map when a tester's WebSocket disconnected — it never unregistered the listeners that handler had registered on the underlying PlaywrightCDPSession. Since a browser page/CDP session can outlive a single test file's connection, a listener registered by one file could still be attached when a later file triggered the same CDP event. The listener would then calltester.cdpEvent(...)on a birpc channel that was already closed, and birpc throws synchronously in that case ([birpc] rpc is closed, cannot call "cdpEvent"). That throw happens inside Playwright's internal event dispatch with nothing to catch it, so it crashes the whole run instead of just failing one test.Fix: added
BrowserServerCDPHandler.dispose(), which callssession.off()for every event the handler ever registered and clears its internal state.removeCDPHandler()now callsdispose()before removing the handler from the map, so no listener is left attached to the CDP session once a tester disconnects.Resolves #10810
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml.Tests
pnpm test:ci(targeted:test/core/test/browser-cdp-handler.test.tsandtest/browser/specs/cdp.test.ts).Documentation
Changesets
feat:,fix:,perf:,docs:, orchore:.Base branch note
This targets
v4directly (notmain) so the fix ships in the next Vitest 4.x patch release.AI disclosure
Claude Code assisted in diagnosing the root cause, implementing the fix, and writing the regression tests for this PR.