Fix the intermittent lhash_test failure on Windows

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)
This commit is contained in:
Tomas Mraz 2024-12-11 15:40:40 +01:00
parent 8ad98cce41
commit be4ce01f9f

View 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;