Review thread safety of client/API/Evaluation context
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
Comece pelos componentes listados: provider/_registry.py, hook/init.py, api.py, _event_support.py, evaluation_context/init.py, transaction_context/init.py, client.py e provider/init.py. Compare o comportamento de concorrência deles com a discussão vinculada do Java SDK. O trabalho estará concluído quando forem criadas issues de acompanhamento específicas para o trabalho de segurança de threads da API global, do cliente e do contexto de avaliação descrito na definição de concluído.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- Python
- Estrelas
- 111
- Forks
- 44
- Merge médio
- 2h 37min
- PRs com merge (30d)
- 14
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de open-feature/python-sdk
-
bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 78/100
open-feature/python-sdk#628 ·
-
question
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 38/100
open-feature/python-sdk#627 ·
-
Spec v0.9.0 compliance Abertav0.9.0
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
open-feature/python-sdk#618 ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
open-feature/python-sdk#615 ·
-
open-feature/python-sdk#584 · 1 responsável ·
Todas as issues de open-feature/python-sdk
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
stephrobert/dsoxlab#238 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
sublimehq/package_control#1780 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
nwg-piotr/nwg-displays#145 ·