Skip to content

Commit 0de5e0c

Browse files
authored
gh-117657: Fix TSAN data race in _PyEval_SetTrace assertion (gh-131561)
The `sys_tracing_threads` variable should be read inside `LOCK_SETUP()`.
1 parent 3e2ccea commit 0de5e0c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Python/legacy_tracing.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,10 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
594594
if (_PySys_Audit(current_tstate, "sys.settrace", NULL) < 0) {
595595
return -1;
596596
}
597-
assert(tstate->interp->sys_tracing_threads >= 0);
598597
// needs to be decref'd outside of the lock
599598
PyObject *old_traceobj;
600599
LOCK_SETUP();
600+
assert(tstate->interp->sys_tracing_threads >= 0);
601601
Py_ssize_t tracing_threads = setup_tracing(tstate, func, arg, &old_traceobj);
602602
UNLOCK_SETUP();
603603
Py_XDECREF(old_traceobj);

0 commit comments

Comments
 (0)