]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix the intermittent lhash_test failure on Windows
authorTomas Mraz <tomas@openssl.org>
Wed, 11 Dec 2024 14:40:40 +0000 (15:40 +0100)
committerTomas Mraz <tomas@openssl.org>
Fri, 13 Dec 2024 07:23:21 +0000 (08:23 +0100)
We must set pending_delete before the actual deletion as another inserting
or deleting thread can pick up the delete callback before the
ossl_ht_write_unlock() call.

This can happen only if no read locks are pending and only on Windows where
we do not use the write mutex to get the callback list.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/26152)

test/lhash_test.c

index 925b84f3cd23ba4dfff33daf6e01dc15452671cc..aa5504c248ad758a89b114419641d015f073bdba 100644 (file)
@@ -613,16 +613,24 @@ static void do_mt_hash_work(void)
         case DO_DELETE:
             ossl_ht_write_lock(m_ht);
             expected_rc = expected_m->in_table;
+            if (expected_rc == 1) {
+                /*
+                 * We must set pending_delete before the actual deletion
+                 * as another inserting or deleting thread can pick up
+                 * the delete callback before the ossl_ht_write_unlock() call.
+                 * This can happen only if no read locks are pending and
+                 * only on Windows where we do not use the write mutex
+                 * to get the callback list.
+                 */
+                expected_m->in_table = 0;
+                CRYPTO_atomic_add(&expected_m->pending_delete, 1, &ret, worker_lock);
+            }
             if (expected_rc != ossl_ht_delete(m_ht, TO_HT_KEY(&key))) {
                 TEST_info("Iteration %d Expected rc %d on delete of element %u which is %s\n",
                           giter, expected_rc, (unsigned int)index,
                           expected_m->in_table ? "in table" : "not in table");
                 worker_exits[num] = "Failure on delete";
             }
-            if (expected_rc == 1) {
-                expected_m->in_table = 0;
-                CRYPTO_atomic_add(&expected_m->pending_delete, 1, &ret, worker_lock); 
-            }
             ossl_ht_write_unlock(m_ht);
             if (worker_exits[num] != NULL)
                 return;