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.
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:
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:
ThreadPoolExecutorTask.Runwith aChannelHandlers should be dispatched via a
ThreadPoolExecutorso 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 aThreadPoolExecutor) 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.