Skip to content

Commit 0e2811f

Browse files
fix: resolve race condition in quorum data recovery thread management
Replace check-then-set pattern with atomic compare-and-swap operation in StartQuorumDataRecoveryThread to prevent multiple threads from being started for the same quorum concurrently. The previous implementation had a race condition where multiple threads could pass the initial check before any of them set the flag, leading to potential resource conflicts and duplicate operations. This change ensures thread-safe access to fQuorumDataRecoveryThreadRunning using compare_exchange_strong, eliminating the race condition window.
1 parent 3b3169d commit 0e2811f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/llmq/quorums.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,11 +923,11 @@ void CQuorumManager::StartQuorumDataRecoveryThread(CConnman& connman, const CQuo
923923
{
924924
assert(m_mn_activeman);
925925

926-
if (pQuorum->fQuorumDataRecoveryThreadRunning) {
926+
bool expected = false;
927+
if (!pQuorum->fQuorumDataRecoveryThreadRunning.compare_exchange_strong(expected, true)) {
927928
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Already running\n", __func__);
928929
return;
929930
}
930-
pQuorum->fQuorumDataRecoveryThreadRunning = true;
931931

932932
workerPool.push([&connman, pQuorum, pIndex, nDataMaskIn, this](int threadId) {
933933
size_t nTries{0};

0 commit comments

Comments
 (0)