GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Data race: `sys.addaudithook()` lazily creates `interp->audit_hooks` with no lock · Issue #154431 · python/cpython

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

New issue
Copy link
New issue
Copy link
Open
Open
Data race: sys.addaudithook() lazily creates interp->audit_hooks with no lock#154431
Copy link
Assignees
sobolevn
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@sobolevn
sobolevn
opened on Jul 22, 2026
Issue body actions

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-154431: Fix data race in sys.audithook #154462
  • [3.15] gh-154431: Fix data race in sys.audithook (GH-154462) #154477
  • [3.14] gh-154431: Fix data race in sys.audithook (GH-154462) #154478
  • gh-154431: Use existing runtime->audit_hooks.mutex instead of a new one #154494
  • gh-154431: Eagerly initialize the audit hooks list #154554
  • gh-154431: Revert "gh-154431: Fix data race in sys.audithook (#154462)" #154769
  • [3.15] gh-154431: Revert "gh-154431: Fix data race in sys.audithook (GH-154462)" (GH-154769) #154774

Activity

  1. sobolevn
    self-assigned this
    on Jul 22, 2026
  2. sobolevn
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    topic-free-threading
    on Jul 22, 2026
  3. sobolevn
    added a commit that references this issue on Jul 22, 2026

    pythongh-154431: Fix data race in `sys.audithook`

    60ef84f
  4. ambv
    added a commit that references this issue on Jul 22, 2026

    gh-154431: Fix data race in `sys.audithook` (#154462)

    596cd5c
  5. sobolevn
    added a commit that references this issue on Jul 22, 2026

    [3.15] gh-154431: Fix data race in `sys.audithook` (GH-154462) (#154477)

    e9d9fd9
  6. devdanzin
    added a parent issue on Jul 23, 2026
    • Free-threading data races in CPython: 15 findings (9 new + 6 residual of existing FT work) #153852
  7. encukou
    added a commit that references this issue on Jul 27, 2026

    gh-154431: Revert "gh-154431: Fix data race in `sys.audithook` (#154462…

    c7b9a13
  8. encukou commented on Jul 27, 2026

    @encukou
    encukou
    on Jul 27, 2026
    Member
    More actions

    The commit caused a refleak that made tier 1 buildbot fail (e.g. [here](e.g. https://buildbot.python.org/#/builders/1610/builds/3726)); it was failing throughout the weekend. I've reverted to get the CI green.
    Please add the change itself (an un-revert) to the follow-up PR(s). Let me know if you want assistance.

  9. ZeroIntensity
    added a commit that references this issue on Jul 27, 2026

    Merge branch 'main' into issues/pythongh-154431-sys-addaudithook-race

    97fe202
  10. encukou
    added a commit that references this issue on Jul 27, 2026

    [3.15] gh-154431: Revert "gh-154431: Fix data race in `sys.audithook` (…

    44fca7e
  11. mbeijen
    added a commit that references this issue on Aug 14, 2026

    pythongh-154431: Revert "pythongh-154431: Fix data race in `sys.audit…

    a3b278f
  12. github-project-automation
    added this to Project_VKon Oct 18, 2026
  13. github-project-automation
    moved this to Todo in Project_VKon Oct 18, 2026
  14. ZeroIntensity
    added a commit that references this issue on Oct 20, 2026

    Merge branch 'main' into issues/pythongh-154431-sys-addaudithook-race

    de12100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @sobolevn
    sobolevn

Labels

extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.