You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an asynchronous predicate passed to Playwright's internal wait_for_event() raises asyncio.CancelledError, the event waiter does not settle its promise or remove the registered event listener.
The issue occurs because asyncio.CancelledError inherits from BaseException rather than Exception in modern Python versions. The current exception handler catches only Exception, so the cancellation bypasses the failure handler.
As a result, the event waiter remains pending indefinitely when no timeout is configured, and the event listener remains registered.
Steps to Reproduce
Run the following script from the Playwright Python repository:
Hi, I'm the Playwright bot. I reproduced this and prepared a fix proposal.
Reproduced on Linux at f31e7025d36bebc4b55c2e94f97f26ac92e13067, with Python 3.12.3. The async predicate task exits on CancelledError, but its waiting future stays pending and its event listener stays registered. The fix removes the listener, passes the original cancellation to the waiter, and re-raises it in the predicate task.
The proposal extends the existing async-predicate error test with cancellation and listener-cleanup checks.
Reproduction and checks
The browser-free check registers an async predicate that raises asyncio.CancelledError("Predicate cancelled"), emits one event, and waits until the predicate has run:
Without a timeout, main leaves promise.done() false and one listener registered. With the fix, the future is done, no listener remains, and awaiting the future raises the original cancellation.
All checks used the driver built from upstream b0e0b7b555e637cc8c0ce94dd98c3be153861333 (1.66.0-next):
Check
Result
Regression without the fix
Cancellation case fails with TimeoutError on Chromium, Firefox and headed WebKit; ordinary exception case passes
Regression with the fix
Both cases pass on headless and headed Chromium/Firefox, and headed WebKit
Async Python page tests and request/response wait tests
WebKit initially lacked host libraries. Its checks used libraries extracted under the run's scratch directory, an isolated launcher that preserves their library path, and Xvfb. The system-cache dependency check was disabled after resolving the shared libraries. Headless WebKit remained blocked by a missing EGL display; the Mesa package download returned HTTP 404. Headed WebKit passed. No system packages were changed.
I also investigated this issue and submitted PR #3380 with a fix and regression test for the same cancellation-handling problem.
I noticed that PR #3380 was closed and a bot-generated PR #3381 was opened for this issue, with a similar approach. I'm glad to see the issue moving toward a fix.
I just wanted to highlight that I had already worked on this solution and submitted a contribution. I would appreciate it if my work in PR #3380 could also be considered.
Could you please clarify whether there was a specific reason my PR was closed in favour of the bot-generated PR?
Activity
microsoft-playwright-automation commentedon Nov 26, 2026
microsoft-playwright-automation commentedon Nov 26, 2026
Hi, I'm the Playwright bot. I reproduced this and prepared a fix proposal.
Reproduced on Linux at
f31e7025d36bebc4b55c2e94f97f26ac92e13067, with Python 3.12.3. The async predicate task exits onCancelledError, but its waiting future stays pending and its event listener stays registered. The fix removes the listener, passes the original cancellation to the waiter, and re-raises it in the predicate task.The proposal extends the existing async-predicate error test with cancellation and listener-cleanup checks.
Reproduction and checks
The browser-free check registers an async predicate that raises
asyncio.CancelledError("Predicate cancelled"), emits one event, and waits until the predicate has run:Without a timeout, main leaves
promise.done()false and one listener registered. With the fix, the future is done, no listener remains, and awaiting the future raises the original cancellation.All checks used the driver built from upstream
b0e0b7b555e637cc8c0ce94dd98c3be153861333(1.66.0-next):TimeoutErroron Chromium, Firefox and headed WebKit; ordinary exception case passes4d36cf076a253e2ef7ff99f933a95291d00dfd9amypy playwright,./scripts/lint.sh,git diff --checkWebKit initially lacked host libraries. Its checks used libraries extracted under the run's scratch directory, an isolated launcher that preserves their library path, and Xvfb. The system-cache dependency check was disabled after resolving the shared libraries. Headless WebKit remained blocked by a missing EGL display; the Mesa package download returned HTTP 404. Headed WebKit passed. No system packages were changed.
Draft PR: #3381
Triaged on Linux by the Playwright bot - agent run
himanshug189-sketch commentedon Nov 26, 2026
Hi,
I also investigated this issue and submitted PR #3380 with a fix and regression test for the same cancellation-handling problem.
I noticed that PR #3380 was closed and a bot-generated PR #3381 was opened for this issue, with a similar approach. I'm glad to see the issue moving toward a fix.
I just wanted to highlight that I had already worked on this solution and submitted a contribution. I would appreciate it if my work in PR #3380 could also be considered.
Could you please clarify whether there was a specific reason my PR was closed in favour of the bot-generated PR?
Thanks for your time.