python / python/cpython

Data race: `sys.addaudithook()` lazily creates `interp->audit_hooks` with no lock

未關閉
#154,431 1 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

@sobolevn 已經在處理了。

開始於 2026年7月22日。

extension-modules topic-free-threading type-bug
主要語言
Python
星號
77.2k
分支
36k
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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。