Review thread safety of client/API/Evaluation context
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with the listed components: provider/_registry.py, hook/init.py, api.py, _event_support.py, evaluation_context/init.py, transaction_context/init.py, client.py, and provider/init.py. Compare their concurrency behavior with the linked Java SDK discussion. Done means creating focused follow-up issues for the global API, client, and evaluation context thread-safety work described in the definition of done.
Written by the indexing model from the issue text.
Description
Review the thread safety of the SDK to make sure there's no potential concurrency issues, particularly around state maintained in the global API object, clients, and evaluation context objects.
See here for a similar discussion in the Java SDK and others.
Background
Python's GIL is sometimes mistaken for making threading a non-issue (like Node's single-threaded model), but they're not the same. The GIL only makes individual bytecode operations atomic; compound operations like check-then-act or read-modify-write are not safe. Providers commonly run background threads for connection management and emit events from them, so these races aren't just theoretical.
Audit
Here's what we found. The only locks in the SDK today are in _event_support.py (and even those have some gaps). Everything else is unprotected.
ProviderRegistrysingleton (provider/_registry.py) - this is the big one. No locks at all.set_provider()andset_default_provider()have check-then-act patterns with side effects (initialize/shutdown), so concurrent calls can double-shutdown, lose providers, or initialize providers that never get registered.clear_providers()has a window where shut-down providers are still returned to callers.- Global
_hookslist (hook/__init__.py) -add_hooksdoes_hooks = _hooks + hookswhich is a read-concat-rebind; two concurrent calls can lose one set of hooks api.clear_providers()(api.py) - callsprovider_registry.clear_providers()then_event_support.clear()as two separate steps; event handlers still exist but providers are gone in between_event_support.py- has RLock (good), but immediate handler execution inadd_*_handlerruns outside the lock, andclear()acquires two separate locks non-atomically- Global
_evaluation_context(evaluation_context/__init__.py) - no lock; TOCTOU across the evaluation pipeline (context can change between read and use) - Global transaction context propagator (
transaction_context/__init__.py) - no lock; read-then-call-method races with propagator swap - Client instance state (
client.py) -self.hookshas the same lost-update pattern as global hooks;_assert_provider_statusreadsself.provideragain instead of using the reference captured earlier in the evaluation flow, so the status check can be for a different provider than the one actually used AbstractProvider._on_emit(provider/__init__.py) -emit()doesif hasattr(self, "_on_emit"): self._on_emit(...)which is a TOCTOU;detach()during shutdown can delete_on_emitwhile a background thread is between the check and the call
Definition of done
- issues created for thread safety of global API, client, and evaluation context
- Dominant language
- Python
- Stars
- 112
- Forks
- 44
- Avg merge
- 3h 15m
- Merged PRs (30d)
- 21
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from open-feature/python-sdk
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 78/100
open-feature/python-sdk#628 ·
Maintainers usually reply within 1 day
-
question
Difficulty 4/5 3-5 days Newbie friendliness 38/100
open-feature/python-sdk#627 ·
Maintainers usually reply within 1 day
-
v0.9.0
Difficulty 5/5 Over a week Newbie friendliness 25/100
open-feature/python-sdk#618 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
open-feature/python-sdk#615 ·
Maintainers usually reply within 1 day
-
Support isolated API instancesMay be free again @marcozabel claimed this 163 days ago, and no pull request is open. Open
open-feature/python-sdk#584 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in open-feature/python-sdk
Similar issues
-
deployment release-lag
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
nolte/kamerplanter#2047 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NousResearch/hermes-plugin-claude-subscription-directsdk#94 ·
Maintainers usually reply within 1 day
-
namespace operations
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
EclipseFdn/open-vsx.org#13702 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day