aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2022-01-26 16:58:32 +0200
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2022-01-28 19:27:25 +0000
commit99a6b699cd650f13d7200d344bf5e2d4b45b20ac (patch)
treea2ac7cd660cc8ee179264fff4a1949d14f4a6ce9 /src
parent83c76467157bbca023bffda0f0bc2f01eb76a040 (diff)
downloadbitcoin-99a6b699cd650f13d7200d344bf5e2d4b45b20ac.tar.xz
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.
Diffstat (limited to 'src')
-rw-r--r--src/banman.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/banman.cpp b/src/banman.cpp
index 87c1bbc89e..b28e3f7f7c 100644
--- a/src/banman.cpp
+++ b/src/banman.cpp
@@ -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(),