fix: drop response frames addressed to another request - #247
Open
bepsvpt wants to merge 1 commit into
Open
Conversation
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.
Summary
Client::execute()breaks its read loop when thewaitUntillifecycle event arrives:Page::goto()always sendswaitUntil: 'load', and theloadevent usually arrives before goto's own response. So the goto response stays in the websocket buffer and is never read. The nextexecute()call reads it, and two problems happen:id. WhenafterEachcloses the context while a goto is not settled yet, Playwright answers that goto late with aTargetClosedError. The next command that reads the socket gets this error. In practice, the next test's first browser operation fails withTarget page, context or browser has been closed(and is marked risky, because it fails before any assertion). If nothing reads the socket untilterminate(),Browser::closethrows instead, and the run exits 1 even when every test passed. The failing test changes from run to run because it depends on timing.This PR skips frames whose
idbelongs to another request, before the error check. Event frames have noid, so they are not affected. Error frames for the current request still throw. ThewaitUntilbreak condition is not changed.Fixes pestphp/pest#1759.
This change is compatible with #241, which fixes hang problems in the same loop and already mentions this issue: "that issue's suggested fix applies cleanly on top of this one".
Verification
I logged every
sendText/receivewith request ids on a real Laravel browser suite (12 tests). Every staleTargetClosedErrorframe came from an abandonedgoto. Results on that suite:Tests
Four unit tests for
Client::execute(), using a stubbedWebsocketConnection(same approach as #241):The first two fail without the
src/change. The last two make sure existing behavior stays the same.AI assistance
Root-cause tracing, fix, and tests: Claude Code (claude-fable-5, xhigh).