Skip to content

fix: ignore CancelledError in sync event listener done callback - #3271

Closed
Reginald Alfret V (reginaldalfret) wants to merge 1 commit into
microsoft:mainfrom
reginaldalfret:fix/reginald-playwright-python-cancelled-route-callback
Closed

Reginald Alfret V (reginaldalfret) wants to merge 1 commit into
microsoft:mainfrom
reginaldalfret:fix/reginald-playwright-python-cancelled-route-callback

Conversation

@reginaldalfret

Copy link
Copy Markdown

Fixes #3266

Summary

In playwright/_impl/_connection.py, _done_callback was calling future.exception() unconditionally. In Python asyncio, calling .exception() on a cancelled future raises asyncio.CancelledError. When exiting sync_playwright() with pending tasks (such as an unanswered route handler), cancelling the task caused an unhandled CancelledError to be logged from the event loop callback.

Changes

  • In Connection.dispatch, guarded _done_callback with if future.cancelled(): return prior to inspecting future.exception().
  • Added unit test test_sync_event_listener_cancelled_future in tests/sync/test_sync.py verifying that cancelled futures attached to event listeners do not raise unhandled errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Python sync API logs CancelledError when exiting sync_playwright() with an unanswered route

2 participants