Fix race condition for SetBannedSetDirty() calls

Another thread can `SetBannedSetDirty(true)` while `CBanDB::Write()`
call being executed. The following `SetBannedSetDirty(false)`
effectively makes `m_is_dirty` flag value inconsistent with the actual
`m_banned` state. Such behavior can result in data loss, e.g., during
shutdown.
pull/826/head
Hennadii Stepanov 3 years ago
parent 83c7646715
commit 99a6b699cd
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

@ -49,11 +49,12 @@ void BanMan::DumpBanlist()
SweepBanned();
if (!BannedSetIsDirty()) return;
banmap = m_banned;
SetBannedSetDirty(false);
}
int64_t n_start = GetTimeMillis();
if (m_ban_db.Write(banmap)) {
SetBannedSetDirty(false);
if (!m_ban_db.Write(banmap)) {
SetBannedSetDirty(true);
}
LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(),

Loading…
Cancel
Save