Skip to content

Commit

Permalink
fix race that could fail to persist a ban (#1518)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OlegGirko authored and UdjinM6 committed Jul 11, 2017
1 parent b47984f commit 9a8a290
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2752,9 +2752,10 @@ void DumpBanlist()

CBanDB bandb;
banmap_t banmap;
CNode::SetBannedSetDirty(false);
CNode::GetBanned(banmap);
if (bandb.Write(banmap))
CNode::SetBannedSetDirty(false);
if (!bandb.Write(banmap))
CNode::SetBannedSetDirty(true);

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

0 comments on commit 9a8a290

Please sign in to comment.