fix: isolate provider event handler dispatch#599
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces asynchronous event handling using a ThreadPoolExecutor to execute OpenFeature event handlers, ensuring they do not block the emitter or other handlers. It also refactors locking mechanisms to release locks before handler execution and wraps handler execution in try-except blocks to prevent a single failing handler from halting subsequent ones. The review feedback recommends avoiding unnecessary mutation and potential memory leaks in defaultdict lookups by checking if keys exist before accessing them in both client and global handler registries.
13de63c to
56e5045
Compare
56e5045 to
fb4e9a1
Compare
|
Updated in the latest push: Re-verified after the change:
|
gruebel
left a comment
There was a problem hiding this comment.
overall looks good and addresses the mentioned issues. added just a few comments, thanks 🍻
0db2460 to
5dfdfd9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #599 +/- ##
==========================================
+ Coverage 98.28% 98.34% +0.06%
==========================================
Files 45 45
Lines 2386 2477 +91
==========================================
+ Hits 2345 2436 +91
Misses 41 41
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Small follow-up after the Codecov report: I added a focused regression test for the read-only client-dispatch no-op path, so Verification after the new commit:
The main build workflow is still waiting for maintainer approval for the fork run, so there is no new CI failure on the latest head yet. |
|
I made some small test improvements, and also shut down the executor on exit. |
0f441d7 to
2bd3e58
Compare
Signed-off-by: Lucas-FManager <265058144+Lucas-FManager@users.noreply.github.com>
Signed-off-by: Lucas-FManager <265058144+Lucas-FManager@users.noreply.github.com>
Signed-off-by: Lucas-FManager <265058144+Lucas-FManager@users.noreply.github.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2bd3e58 to
a049b00
Compare
Problem
Provider event handlers currently execute synchronously while the handler registry lock is held. That means a handler exception can stop later handlers, and a slow handler can block the provider/client path that emitted the event.
Approach
ThreadPoolExecutor.Security
This avoids running arbitrary user event-handler code while internal handler registries are locked. It also keeps handler exceptions contained to the callback boundary instead of propagating into SDK/provider control flow.
Verification
uv run pytest tests -q-> 158 passeduvx ruff check openfeature/_event_support.py tests/test_client.py tests/test_api.py-> passeduvx ruff format --check openfeature/_event_support.py tests/test_client.py tests/test_api.py-> passedgit diff --check-> passedFixes #596