Skip to content

Commit 99a6b69

Browse files
committed
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.
1 parent 83c7646 commit 99a6b69

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/banman.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ void BanMan::DumpBanlist()
4949
SweepBanned();
5050
if (!BannedSetIsDirty()) return;
5151
banmap = m_banned;
52+
SetBannedSetDirty(false);
5253
}
5354

5455
int64_t n_start = GetTimeMillis();
55-
if (m_ban_db.Write(banmap)) {
56-
SetBannedSetDirty(false);
56+
if (!m_ban_db.Write(banmap)) {
57+
SetBannedSetDirty(true);
5758
}
5859

5960
LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(),

0 commit comments

Comments
 (0)