fix(client): release in-flight commands when the connection dies - #630
Merged
Conversation
`send_message` waited out `:protocol_timeout` before checking whether the socket was still there, so every command in flight when the browser died paid the full timeout, and so did every command issued afterwards. A dead browser turned into a long parade of slow failures instead of one fast one. The dispatch loop now releases the pending commands once the message queue closes, and a command sent after that raises `DeadBrowserError` without waiting at all. Refs #470
This was referenced Sep 2, 2026
…death The crash spec timed how long Chrome takes to die, which the dockerized browser on CI doesn't answer quickly enough, and it left the shared browser dead for every spec after it. The connection is now closed under a command directly, on its own browser.
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.
Refs #470.
The problem
Client#send_messagewaits for the response and only afterwards asks whether the connection is still alive:So when the browser dies, nothing wakes the commands already in flight, and nothing stops new ones from being sent into a closed socket either. Each pays the full
:protocol_timeoutbefore raising. In a test suite that means one dead browser turns into hundreds of failures at five seconds apiece, which is a good part of what makes #470's collapse so slow and so hard to read.The fix
The dispatch loop releases the pending commands as soon as the message queue closes, and a command sent after that raises
DeadBrowserErrorimmediately:No new error classes and no change to what callers see, only when they see it:
DeadBrowserErrorwas already what these paths raised, just five seconds later.Verification
spec/browser_spec.rb#crash: crashing the browser raisesDeadBrowserErrorin under 2s, and so does the next command against the dead browser. Before the fix the first assertion fails at the full 5s timeout.