Skip to content

Commit 48054d2

Browse files
[3.13] gh-117657: Fix TSAN race in QSBR assertion (GH-119887) (#119904)
Due to a limitation in TSAN, all reads from `PyThreadState.state` must be atomic to avoid reported races. (cherry picked from commit 90ec19f) Co-authored-by: Sam Gross <colesbury@gmail.com>
1 parent 48f3378 commit 48054d2

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

Python/qsbr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ qsbr_poll_scan(struct _qsbr_shared *shared)
160160
bool
161161
_Py_qsbr_poll(struct _qsbr_thread_state *qsbr, uint64_t goal)
162162
{
163-
assert(_PyThreadState_GET()->state == _Py_THREAD_ATTACHED);
163+
assert(_Py_atomic_load_int_relaxed(&_PyThreadState_GET()->state) == _Py_THREAD_ATTACHED);
164+
164165
if (_Py_qbsr_goal_reached(qsbr, goal)) {
165166
return true;
166167
}

Tools/tsan/suppressions_free_threading.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ race_top:_PyFrame_GetCode
7676
race_top:_PyFrame_Initialize
7777
race_top:PyInterpreterState_ThreadHead
7878
race_top:_PyObject_TryGetInstanceAttribute
79-
race_top:_Py_qsbr_unregister
80-
race_top:_Py_qsbr_poll
8179
race_top:PyThreadState_Next
8280
race_top:Py_TYPE
8381
race_top:PyUnstable_InterpreterFrame_GetLine

0 commit comments

Comments
 (0)