This PR adds a proper thread safety annotation to BanMan::SweepBanned()
.
Also a simple refactoring applied.
BanMan::SweepBanned()
#25149
This PR adds a proper thread safety annotation to BanMan::SweepBanned()
.
Also a simple refactoring applied.
02022-05-16T21:20:13.025586Z (mocktime: 1970-01-01T00:12:57Z) [test] [net_types.cpp:63] [BanMapFromJson] Dropping entry with unknown version (2) from ban list
1Assertion failed: lock m_cs_banned not held in banman.cpp:176; locks held:
2make[3]: *** [Makefile:20916: test/banman_tests.cpp.test] Error 1
Concept ACK
Looks like a m_cs_banned
lock acquire needs to add before the the SweepBanned
call in the BanMan
constructor to get rid of the failed assertion.
{ LoadBanlist(); DumpBanlist(); }
causes the compiler to give errors about the missing locks in LoadBanlist()
.
AssertLockHeld
and remove it here?
Reworked: c4d0613bdf3beaf48fd35625cf2dc6018b059dbb -> f317ae181dc03cbe7004b63996dc7cf2c85c84db (pr25149.01 -> pr25149.02).
PR description has been updated as well.
Doing:
0BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time)
1 : m_client_interface(client_interface), m_ban_db(std::move(ban_file)), m_default_ban_time(default_ban_time)
2{
3 LoadBanlist();
4 DumpBanlist();
5}
6
7void BanMan::LoadBanlist()
8{
9 LOCK(m_cs_banned);
10
11 if (m_client_interface) m_client_interface->InitMessage(_("Loading banlist…").translated);
12
13 int64_t n_start = GetTimeMillis();
14 if (m_ban_db.Read(m_banned)) {
15 SweepBanned(); // sweep out unused entries
16
17 LogPrint(BCLog::NET, "Loaded %d banned node addresses/subnets %dms\n", m_banned.size(),
18 GetTimeMillis() - n_start);
19 } else {
20 LogPrintf("Recreating the banlist database\n");
21 m_banned = {};
22 m_is_dirty = true;
23 }
24}
looks cleaner to me, fwiw. Just explicitly taking the lock in the constructor seems simpler than delegating to SweepBanMan()
which takes the lock then calls SweepBanMan_()
too…
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Co-authored-by: Anthony Towns <aj@erisian.com.au>
Code-review ACK ab7538832043a6c15e45a178fb6bb6298a00108f
Happy to see that another RecursiveMutex
will bite the dust soon.