Repository navigation
Description
Version
Playwright Python: 0.1.dev1199+g8b4525108.d20261124
Steps to reproduce
Scenario 1: Errors from unrelated events are suppressed
- Create an
EventEmitterinstance. - Register an asynchronous listener for event
a. - Register another asynchronous listener for event
b. - Make both listeners wait on an asynchronous future/event before raising an exception.
- Call
remove_all_listeners("a", "ignoreErrors")while both handlers are still pending. - Release both handlers so they raise exceptions.
- Observe which errors are reported.
Scenario 2: Errors from listeners added later are suppressed
- Create an
EventEmitterinstance. - Call
remove_all_listeners("a", "ignoreErrors"). - Register a new asynchronous listener for event
b. - Make the listener raise an exception.
- Trigger event
b. - Observe whether the listener error is reported.
Validation
The regression tests demonstrate both scenarios.
After the fix, the following tests pass:
python -m pytest tests/async/test_event_emitter.py -qResult: 6 passed
Related regression tests:
python -m pytest tests/async/test_event_emitter.py tests/async/library/test_unroute_behavior.py -qResult: 54 passed
Expected behavior
ignoreErrorsshould suppress errors only from the asynchronous handlers that were already pending for the event(s) being removed whenremove_all_listenerswas called.- Errors from pending handlers belonging to unrelated events should still be reported.
- Errors from listeners registered after
remove_all_listeners(..., "ignoreErrors")should not be suppressed. - The behavior should be scoped to the relevant pending handler futures rather than applied globally.
Actual behavior
The current rejection-handling mechanism uses a global error-suppression handler/state.
As a result:
- Calling
remove_all_listeners("a", "ignoreErrors")can suppress errors from pending handlers belonging to eventb. - Errors from listeners registered after the removal operation can also be suppressed unexpectedly.
This causes unrelated listener failures to go unreported.
Additional context
The issue appears to be related to how asynchronous listener errors are tracked and suppressed inside the Python EventEmitter implementation.
The suppression should be associated with individual pending handler futures instead of using a global rejection handler.
The behavior is particularly problematic when multiple event types have asynchronous handlers running concurrently.
Environment
- OS: Linux (Ubuntu)
- Python: 3.12.3
- pytest: 7.4.4
- pytest-asyncio: 1.5.0
- Browsers tested: Chromium, Firefox, WebKit
- Repository: `microsoft/playwright-python`
Activity