Skip to content

Event handler error isolation and async execution #596

@toddbaert

Description

@toddbaert

Several issues with event handler invocation in _event_support.py:

1. No error isolation (spec 5.2.5 violation)

Handler calls (lines 33, 39, 101) have no try/except. If a handler raises, subsequent handlers won't run.

Spec 5.2.5:

If a handler function terminates abnormally, other handler functions MUST run.

2. Handlers block the emitting thread

Handlers run synchronously on the calling thread, and under a lock. A slow handler blocks all event operations. Other SDKs dispatch handlers asynchronously:

  • Java submits each handler to a ThreadPoolExecutor
  • Go launches a goroutine per handler
  • .NET processes events on a background thread via Task.Run with a Channel

Handlers should be dispatched via a ThreadPoolExecutor so they don't block the emitter.

3. Potential deadlocks

Because handlers execute while holding an RLock, a provider or handler that interacts with the event system from a different thread during handling could deadlock. Dispatching handlers outside the lock (e.g., via a ThreadPoolExecutor) would eliminate this risk.

Testing

There are currently no tests covering handler error isolation. Tests should be added to verify that a raising handler does not prevent subsequent handlers from running.

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.0-releaseRequired for a 1.0 releasebugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions