fix(asyncio): do not hang when async_playwright() is cancelled while connecting - #3177
Open
Yury Semikhatsky (yury-s) wants to merge 3 commits into
Open
fix(asyncio): do not hang when async_playwright() is cancelled while connecting#3177Yury Semikhatsky (yury-s) wants to merge 3 commits into
Yury Semikhatsky (yury-s) wants to merge 3 commits into
Conversation
…connecting Cancelling __aenter__ left the driver process and the transport tasks running with no owner. At loop shutdown the init task absorbed its one cancellation inside Channel._abort() waiting for a reply that could never arrive, so asyncio.run() never returned. - stop the connection when __aenter__ is cancelled - allow PipeTransport.request_stop() before the driver has spawned - release pending protocol callbacks when the Connection.run() task is cancelled at loop shutdown - retrieve callback exceptions in Channel._abort() even when its wait is interrupted by another cancellation Fixes: microsoft/playwright#42296
- reuse __aexit__ for teardown when __aenter__ fails or is cancelled, mirroring the sync context manager - move _stopped_future and wait_until_stopped() into the Transport base, deleting both subclass copies - reuse request_stop() when connect() finishes after a stop request - skip sending __abort__ over a closed connection
Yury Semikhatsky (yury-s)
requested review from
Simon Knott (Skn0tt),
Dmitry Gozman (dgozman) and
Pavel Feldman (pavelfeldman)
August 19, 2026 00:38
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
__aenter__fails or is cancelled, reusing__aexit__like the sync context manager doesPipeTransport.request_stop()before the driver has spawnedConnection.run()task is cancelled at loop shutdown, so their cancellation is not absorbed byChannel._abort()waiting for a reply that can never arriveChannel._abort()even when its wait is interrupted by another cancellationFixes microsoft/playwright#42296