Skip to content

Commit 94fbe97

Browse files
[3.13] gh-117657: Fix TSAN data race in _PyEval_SetTrace assertion (gh-131561) (#131564)
The `sys_tracing_threads` variable should be read inside `LOCK_SETUP()`. (cherry picked from commit 0de5e0c) Co-authored-by: Sam Gross <colesbury@gmail.com>
1 parent 55fb3a7 commit 94fbe97

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: Python/legacy_tracing.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,10 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
596596
if (_PySys_Audit(current_tstate, "sys.settrace", NULL) < 0) {
597597
return -1;
598598
}
599-
assert(tstate->interp->sys_tracing_threads >= 0);
600599
// needs to be decref'd outside of the lock
601600
PyObject *old_traceobj;
602601
LOCK_SETUP();
602+
assert(tstate->interp->sys_tracing_threads >= 0);
603603
Py_ssize_t tracing_threads = setup_tracing(tstate, func, arg, &old_traceobj);
604604
UNLOCK_SETUP();
605605
Py_XDECREF(old_traceobj);

0 commit comments

Comments
 (0)