Skip to content

Commit 397f847

Browse files
colesburymiss-islington
authored andcommitted
pythongh-117657: Fix TSAN race in QSBR assertion (pythonGH-119887)
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 a055984 commit 397f847

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

‎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
@@ -78,8 +78,6 @@ race_top:_PyFrame_GetCode
7878
race_top:_PyFrame_Initialize
7979
race_top:PyInterpreterState_ThreadHead
8080
race_top:_PyObject_TryGetInstanceAttribute
81-
race_top:_Py_qsbr_unregister
82-
race_top:_Py_qsbr_poll
8381
race_top:PyThreadState_Next
8482
race_top:Py_TYPE
8583
race_top:PyUnstable_InterpreterFrame_GetLine

0 commit comments

Comments
 (0)