https://github.com/python/cpython/commit/0de5e0c5442abddbe17481ef450e4abc992058f5
commit: 0de5e0c5442abddbe17481ef450e4abc992058f5
branch: main
author: Sam Gross <colesb...@gmail.com>
committer: colesbury <colesb...@gmail.com>
date: 2025-03-21T14:22:37-04:00
summary:

gh-117657: Fix TSAN data race in _PyEval_SetTrace assertion (gh-131561)

The `sys_tracing_threads` variable should be read inside `LOCK_SETUP()`.

files:
M Python/legacy_tracing.c

diff --git a/Python/legacy_tracing.c b/Python/legacy_tracing.c
index bafc2356280b37..d308a2a40992c6 100644
--- a/Python/legacy_tracing.c
+++ b/Python/legacy_tracing.c
@@ -594,10 +594,10 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc 
func, PyObject *arg)
     if (_PySys_Audit(current_tstate, "sys.settrace", NULL) < 0) {
         return -1;
     }
-    assert(tstate->interp->sys_tracing_threads >= 0);
     // needs to be decref'd outside of the lock
     PyObject *old_traceobj;
     LOCK_SETUP();
+    assert(tstate->interp->sys_tracing_threads >= 0);
     Py_ssize_t tracing_threads = setup_tracing(tstate, func, arg, 
&old_traceobj);
     UNLOCK_SETUP();
     Py_XDECREF(old_traceobj);

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to