Skip to content

Commit

Permalink
Fix the intermittent lhash_test failure on Windows
Browse files Browse the repository at this point in the history
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 openssl#26152)
  • Loading branch information
t8m committed Dec 13, 2024
1 parent 8ad98cc commit be4ce01
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions test/lhash_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit be4ce01

Please sign in to comment.