Data race: `sys.addaudithook()` lazily creates `interp->audit_hooks` with no lock
未关闭
@sobolevn 已经在做这个了。
开始于 2026年7月22日。
extension-modules
topic-free-threading
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Full report: https://gist.github.com/devdanzin/0b13838fd6089e73a3f063ed8f68e733
Repro:
import sys, threading
assert not sys._is_gil_enabled(), "run free-threaded: PYTHON_GIL=0"
NADD = 24 # threads slamming the first-time lazy-init store (write @540) at once
NAUD = 8 # threads spinning audit events (should_audit read @239)
barrier = threading.Barrier(NADD + NAUD)
def _hook(*a):
return None
def adder():
barrier.wait()
for _ in range(200):
sys.addaudithook(_hook) # write interp->audit_hooks (first time) @540
def auditor():
barrier.wait()
for _ in range(200000):
sys.audit("fusil.tsan.test") # should_audit read of interp->audit_hooks @239
ts = [threading.Thread(target=adder) for _ in range(NADD)]
ts += [threading.Thread(target=auditor) for _ in range(NAUD)]
for t in ts: t.start()
for t in ts: t.join()
print("done, no crash")
The fix is incoming.
Linked PRs
- gh-154462
- gh-154477
- gh-154478
- gh-154494
- gh-154554
- gh-154769
- gh-154774
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。