Review thread safety of client/API/Evaluation context
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从列出的组件开始:provider/_registry.py、hook/init.py、api.py、_event_support.py、evaluation_context/init.py、transaction_context/init.py、client.py 和 provider/init.py。将它们的并发行为与链接的 Java SDK 讨论进行比较。完成的标准是:针对完成定义中所描述的全局 API、客户端和评估上下文线程安全工作,创建范围明确的后续 issue。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Python
- 星标
- 113
- 派生
- 48
- 平均合并
- 23 小时 52 分钟
- 30 天内合并 PR
- 20
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
open-feature/python-sdk 的其他 Issue
-
[BUG] before hooks do not receive the evaluation context returned by earlier before hooks可能已有人在做 @Ritinpaul 于 52 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 78/100
open-feature/python-sdk#628 · 1 条评论 ·
维护者通常 1 天内回复
-
question
难度 4/5 3-5 天 新手友好度 38/100
open-feature/python-sdk#627 · 1 条评论 ·
维护者通常 1 天内回复
-
v0.9.0
难度 5/5 一周以上 新手友好度 25/100
open-feature/python-sdk#618 · 1 条评论 ·
维护者通常 1 天内回复
-
Supply the bound domain to provider initialization可能已有人在做 @jonathannorris 于 148 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 55/100
open-feature/python-sdk#615 ·
维护者通常 1 天内回复
-
Support isolated API instances可能已有人在做 @marcozabel 于 219 天前认领。 未关闭
open-feature/python-sdk#584 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 open-feature/python-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
documentation good first issue help wanted
难度 1/5 1 小时以内 新手友好度 90/100
-
documentation good first issue help wanted
难度 1/5 1 小时以内 新手友好度 88/100
-
documentation good first issue help wanted
难度 2/5 1-3 小时 新手友好度 78/100
-
good first issue help wanted
难度 2/5 1-3 小时 新手友好度 82/100