From f4ac02ee7c6530c273503d8575a492e9b2ac1f13 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 27 Apr 2016 09:26:33 -0700 Subject: [PATCH] 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. --- src/net.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 7dec8fc1c..f566af24c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2634,9 +2634,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);