Skip to content

Commit f4ac02e

Browse files
committed
fix race that could fail to persist a ban
DumpBanList currently does this: - with lock: take a copy of the banmap - perform I/O (write out the banmap) - with lock: mark the banmap non-dirty If a new ban is added during the I/O operation, it may never be persisted to disk. Reorder operations so that the data to be persisted cannot be older than the time at which the banmap was marked non-dirty.
1 parent 08b37c5 commit f4ac02e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,9 +2634,10 @@ void DumpBanlist()
26342634

26352635
CBanDB bandb;
26362636
banmap_t banmap;
2637+
CNode::SetBannedSetDirty(false);
26372638
CNode::GetBanned(banmap);
2638-
if (bandb.Write(banmap))
2639-
CNode::SetBannedSetDirty(false);
2639+
if (!bandb.Write(banmap))
2640+
CNode::SetBannedSetDirty(true);
26402641

26412642
LogPrint("net", "Flushed %d banned node ips/subnets to banlist.dat %dms\n",
26422643
banmap.size(), GetTimeMillis() - nStart);

0 commit comments

Comments
 (0)