From 47186880d605cb9723e5753bab81589aa53768d7 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Tue, 17 Jun 2025 20:36:01 +0000 Subject: [PATCH] gh-135641: Fix flaky test_lock_two_threads test case The mutex may have the _Py_HAS_PARKED bit set in rare cases. --- Modules/_testinternalcapi/test_lock.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/_testinternalcapi/test_lock.c b/Modules/_testinternalcapi/test_lock.c index 8d678412fe7179..8d8cb992b0e07f 100644 --- a/Modules/_testinternalcapi/test_lock.c +++ b/Modules/_testinternalcapi/test_lock.c @@ -57,7 +57,10 @@ lock_thread(void *arg) _Py_atomic_store_int(&test_data->started, 1); PyMutex_Lock(m); - assert(m->_bits == 1); + // gh-135641: in rare cases the lock may still have `_Py_HAS_PARKED` set + // (m->_bits == 3) due to bucket collisions in the parking lot hash table + // between this mutex and the `test_data.done` event. + assert(m->_bits == 1 || m->_bits == 3); PyMutex_Unlock(m); assert(m->_bits == 0);