open-feature / python-sdk

Python SDK for OpenFeature
https://openfeature.dev
Apache License 2.0
47 stars 16 forks source link

fix: event handler methods are not thread-safe #329

Closed federicobond closed 3 months ago

federicobond commented 3 months ago

The _client_handlers dictionary allowed modifications during iteration without proper concurrency control. I added some reentrant locks to manage concurrent access to the _global_handlers and _client_handlers data structures.

See #326

Perhaps there is a way to implement some finer-grained concurrency control? The Java SDK uses a ConcurrentHashMap that allows retrieval operations without locking, but I haven't looked into the details.

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.41%. Comparing base (c3ad697) to head (3427796).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #329 +/- ## ========================================== + Coverage 97.34% 97.41% +0.07% ========================================== Files 26 26 Lines 1206 1240 +34 ========================================== + Hits 1174 1208 +34 Misses 32 32 ``` | [Flag](https://app.codecov.io/gh/open-feature/python-sdk/pull/329/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-feature) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/open-feature/python-sdk/pull/329/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-feature) | `97.41% <100.00%> (+0.07%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-feature#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.