python / python/cpython

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

Aperta
#154,431 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@sobolevn ci sta già lavorando.

Dal 22/7/2026.

extension-modules topic-free-threading type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.