Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c7b9a13

Browse filesBrowse files
authored
gh-154431: Revert "gh-154431: Fix data race in sys.audithook (#154462)" (GH-154769)
This commit caused a refleak. This reverts commit 596cd5c.
1 parent 7961bbf commit c7b9a13
Copy full SHA for c7b9a13

5 files changed

+8-35Lines changed: 8 additions & 35 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Include/internal/pycore_interp_structs.h‎

Copy file name to clipboardExpand all lines: Include/internal/pycore_interp_structs.h
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,6 @@ struct _is {
977977
struct _obmalloc_state *obmalloc;
978978

979979
PyObject *audit_hooks;
980-
PyMutex audit_hooks_mutex;
981980
PyType_WatchCallback type_watchers[TYPE_MAX_WATCHERS];
982981
PyCode_WatchCallback code_watchers[CODE_MAX_WATCHERS];
983982
PyContext_WatchCallback context_watchers[CONTEXT_MAX_WATCHERS];
Collapse file

‎Lib/test/test_free_threading/test_sys.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_free_threading/test_sys.py
-14Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,6 @@ def worker(worker_id):
4444
workers = [lambda: worker(i) for i in range(5)]
4545
threading_helper.run_concurrently(workers)
4646

47-
def test_sys_audit_hooks(self):
48-
def _hook(*args):
49-
return None
50-
51-
def adder():
52-
for _ in range(100):
53-
sys.addaudithook(_hook)
54-
55-
def auditor():
56-
for _ in range(2000):
57-
sys.audit("fusil.tsan.test")
58-
59-
threading_helper.run_concurrently([adder, auditor])
60-
6147

6248
if __name__ == "__main__":
6349
unittest.main()
Collapse file

‎Misc/NEWS.d/next/Library/2026-07-22-12-42-53.gh-issue-154431.U2kXXZ.rst‎

Copy file name to clipboardExpand all lines: Misc/NEWS.d/next/Library/2026-07-22-12-42-53.gh-issue-154431.U2kXXZ.rst
-1Lines changed: 0 additions & 1 deletion
This file was deleted.
Collapse file

‎Python/pystate.c‎

Copy file name to clipboardExpand all lines: Python/pystate.c
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ init_interpreter(PyInterpreterState *interp,
578578
llist_init(&interp->mem_free_queue.head);
579579
llist_init(&interp->asyncio_tasks_head);
580580
interp->asyncio_tasks_lock = (PyMutex){0};
581-
interp->audit_hooks_mutex = (PyMutex){0};
582581
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
583582
interp->monitors.tools[i] = 0;
584583
}
Collapse file

‎Python/sysmodule.c‎

Copy file name to clipboardExpand all lines: Python/sysmodule.c
+8-18Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ should_audit(PyInterpreterState *interp)
236236
return 0;
237237
}
238238
return (interp->runtime->audit_hooks.head
239-
|| FT_ATOMIC_LOAD_PTR_ACQUIRE(interp->audit_hooks)
239+
|| interp->audit_hooks
240240
|| PyDTrace_AUDIT_ENABLED());
241241
}
242242

@@ -306,14 +306,13 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
306306
}
307307

308308
/* Call interpreter hooks */
309-
PyObject *audit_hooks = FT_ATOMIC_LOAD_PTR_ACQUIRE(is->audit_hooks);
310-
if (audit_hooks) {
309+
if (is->audit_hooks) {
311310
eventName = PyUnicode_FromString(event);
312311
if (!eventName) {
313312
goto exit;
314313
}
315314

316-
hooks = PyObject_GetIter(audit_hooks);
315+
hooks = PyObject_GetIter(is->audit_hooks);
317316
if (!hooks) {
318317
goto exit;
319318
}
@@ -537,29 +536,20 @@ sys_addaudithook_impl(PyObject *module, PyObject *hook)
537536
}
538537

539538
PyInterpreterState *interp = tstate->interp;
540-
PyMutex mutex = interp->audit_hooks_mutex;
541-
PyMutex_Lock(&mutex);
542-
543539
if (interp->audit_hooks == NULL) {
544-
PyObject *new_list = PyList_New(0);
545-
if (new_list == NULL) {
546-
goto error;
540+
interp->audit_hooks = PyList_New(0);
541+
if (interp->audit_hooks == NULL) {
542+
return NULL;
547543
}
548544
/* Avoid having our list of hooks show up in the GC module */
549-
PyObject_GC_UnTrack(new_list);
550-
FT_ATOMIC_STORE_PTR_RELEASE(interp->audit_hooks, new_list);
545+
PyObject_GC_UnTrack(interp->audit_hooks);
551546
}
552547

553548
if (PyList_Append(interp->audit_hooks, hook) < 0) {
554-
goto error;
549+
return NULL;
555550
}
556551

557-
PyMutex_Unlock(&mutex);
558552
Py_RETURN_NONE;
559-
560-
error:
561-
PyMutex_Unlock(&mutex);
562-
return NULL;
563553
}
564554

565555
/*[clinic input]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.