Skip to content

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

Description

@sobolevn

Bug report

Full report: https://gist.github.com/devdanzin/0b13838fd6089e73a3f063ed8f68e733

Repro:

importsys, threadingassertnotsys._is_gil_enabled(), "run free-threaded: PYTHON_GIL=0"NADD=24# threads slamming the first-time lazy-init store (write @540) at onceNAUD=8# threads spinning audit events (should_audit read @239)barrier=threading.Barrier(NADD+NAUD)
def_hook(*a):
returnNonedefadder():
barrier.wait()
for_inrange(200):
sys.addaudithook(_hook) # write interp->audit_hooks (first time) @540defauditor():
barrier.wait()
for_inrange(200000):
sys.audit("fusil.tsan.test") # should_audit read of interp->audit_hooks @239ts= [threading.Thread(target=adder) for_inrange(NADD)]
ts+= [threading.Thread(target=auditor) for_inrange(NAUD)]
fortints: t.start()
fortints: t.join()
print("done, no crash")

The fix is incoming.

Linked PRs

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions