]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-135641: Fix flaky `test_capi.test_lock_two_threads` test case (gh-135642)
authorSam Gross <colesbury@gmail.com>
Wed, 18 Jun 2025 18:24:05 +0000 (14:24 -0400)
committerGitHub <noreply@github.com>
Wed, 18 Jun 2025 18:24:05 +0000 (14:24 -0400)
The mutex may have the `_Py_HAS_PARKED` bit set.

Modules/_testinternalcapi/test_lock.c

index 8d678412fe717917f82ab8ab51b6f353d3facbbd..8d8cb992b0e07fc66e3282d00e005910827ac630 100644 (file)
@@ -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);