diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2022-01-26 16:58:32 +0200 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2022-01-28 19:27:25 +0000 |
commit | 99a6b699cd650f13d7200d344bf5e2d4b45b20ac (patch) | |
tree | a2ac7cd660cc8ee179264fff4a1949d14f4a6ce9 | |
parent | 83c76467157bbca023bffda0f0bc2f01eb76a040 (diff) |
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.
-rw-r--r-- | src/banman.cpp | 5 |
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(), |