Repository navigation
fix: dispatch close command before raising unhandled event listener error - #3294
Closed
Alok Pandey (alok-108) wants to merge 1 commit into
Closed
Alok Pandey (alok-108) wants to merge 1 commit into
Alok Pandey (alok-108) wants to merge 1 commit into
Conversation
Author
|
Pavel Feldman (@pavelfeldman) could you please take a look when you have a moment? Thank you! |
Collaborator
|
I don't think that special-casing |
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.
Fixes #3293
Problem
When an unhandled exception is raised in an event listener (e.g.
page.on("response", ...)),Connection._on_event_listener_errorstores the exception inself._errorto be raised on the next API call.However,
Connection.send_message_to_server()previously checked:When user code runs cleanup in
finally:or via context manager__exit__, callingbrowser.close()orcontext.close()invokessend_message_to_server("close"). Because"close"and"dispose"were not exempted, the method aborted before transmitting the message to the driver. As a result, the driver never received theclosecommand, and browser child processes were leaked in the background (browser.is_connected() == True).Solution
Connection.send_message_to_server(), exempt"close"and"dispose"from pre-dispatch abortion so that teardown and disposal commands are actually sent to the driver.Connection.dispatch(), when the server responds to"close", ifself._errorwas set, reject the close callback with that error. This delivers the exception to the caller while guaranteeing that the remote browser/page was cleanly terminated on the server beforehand.tests/common/test_events.pyverifying thatbrowser.close()terminates the browser (assert not browser.is_connected()) even when an event listener threw an error.