Skip to content

[Bug]: remove_all_listeners(..., "ignoreErrors") suppresses errors from unrelated event handlers #3388

Backlog

Description

@himanshug189-sketch

Version

Playwright Python: 0.1.dev1199+g8b4525108.d20261124

Steps to reproduce

Scenario 1: Errors from unrelated events are suppressed

  1. Create an EventEmitter instance.
  2. Register an asynchronous listener for event a.
  3. Register another asynchronous listener for event b.
  4. Make both listeners wait on an asynchronous future/event before raising an exception.
  5. Call remove_all_listeners("a", "ignoreErrors") while both handlers are still pending.
  6. Release both handlers so they raise exceptions.
  7. Observe which errors are reported.

Scenario 2: Errors from listeners added later are suppressed

  1. Create an EventEmitter instance.
  2. Call remove_all_listeners("a", "ignoreErrors").
  3. Register a new asynchronous listener for event b.
  4. Make the listener raise an exception.
  5. Trigger event b.
  6. 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 -q

Result: 6 passed

Related regression tests:

python -m pytest tests/async/test_event_emitter.py tests/async/library/test_unroute_behavior.py -q

Result: 54 passed

Expected behavior

  • ignoreErrors should suppress errors only from the asynchronous handlers that were already pending for the event(s) being removed when remove_all_listeners was 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 event b.
  • 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

  1. microsoft-playwright-automation commented on Dec 2, 2026

    @microsoft-playwright-automation
  2. microsoft-playwright-automation commented on Dec 2, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot. I reproduced this in both Python and Node.js on Linux.

    The existing fix in microsoft/playwright#44452 passes the independent regression test. This is the same bug as microsoft/playwright#44430: the emitter-wide rejection handler suppresses unrelated and later listener errors. The fix tracks only the selected pending promises.

    Python main is still affected. I did not propose a second fix: the upstream PR is still a draft, and Python needs to port the change after it merges.

    Reproduction and checks

    The regression starts pending handlers for a and b, removes a with ignoreErrors, then registers and emits a new a handler. All three handlers reject. Only the original a error should be suppressed; both main branches report no errors instead.

    import asyncio
    from playwright._impl.event_emitter import EventEmitter
    
    async def reproduce() -> None:
        ee = EventEmitter()
        errors: list[BaseException] = []
        ee.on("error", errors.append)
        loop = asyncio.get_running_loop()
        removed, unrelated, later = [loop.create_future() for _ in range(3)]
        ee.on("a", lambda: removed)
        ee.on("b", lambda: unrelated)
        ee.emit("a")
        ee.emit("b")
        await ee.remove_all_listeners("a", "ignoreErrors")
        ee.on("a", lambda: later)
        ee.emit("a")
        handled = asyncio.gather(removed, unrelated, later, return_exceptions=True)
        for future, name in zip(
            [removed, unrelated, later], ["removed", "unrelated", "later"]
        ):
            future.set_exception(RuntimeError(name))
        await handled
        assert [str(error) for error in errors] == ["unrelated", "later"]
    
    asyncio.run(reproduce())
    Code tested Checks on Linux Result
    Python main dac790d8533c819a6fba44438999c4e067aea32d Independent regression, Chromium/Firefox/WebKit selections Fails in all three
    Python #3389 088896797a4c2db1eab12a68d293d2306895f182 Independent regression and its two submitted tests, all three selections 9 passed
    JavaScript main 1ccfd514654a25046ff5686da864d5312abac631 (1.66.0-next) Independent extension of EE-032, Chromium project Fails
    microsoft/playwright#44452 4dae51dc122e2d35d88b74acd08fd0fb0af4cb83 All emitter tests, all three projects 171 passed
    Same upstream PR, with the independent regression Listener-removal test file, all three projects 12 passed

    These are emitter-only checks: no browser is launched. The runtimes were Python 3.12.3 and Node.js 24.22.3. The upstream PR build passed after restoring its locked dependencies.

    Triaged on Linux by the Playwright bot - agent run

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-triage-done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions