New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Add thread safety annotation to BanMan::SweepBanned()
#25149
Conversation
2022-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
Assertion failed: lock m_cs_banned not held in banman.cpp:176; locks held:
make[3]: *** [Makefile:20916: test/banman_tests.cpp.test] Error 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Moving the code that's in the constructor into a separate function, so that the constructor is just |
A constructor shouldn't need to lock a member mutex. Maybe we should fade out |
ac1deb7
to
f317ae1
Compare
Reworked: c4d0613 -> f317ae1 (pr25149.01 -> pr25149.02). PR description has been updated as well. |
Doing: BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time)
: m_client_interface(client_interface), m_ban_db(std::move(ban_file)), m_default_ban_time(default_ban_time)
{
LoadBanlist();
DumpBanlist();
}
void BanMan::LoadBanlist()
{
LOCK(m_cs_banned);
if (m_client_interface) m_client_interface->InitMessage(_("Loading banlist…").translated);
int64_t n_start = GetTimeMillis();
if (m_ban_db.Read(m_banned)) {
SweepBanned(); // sweep out unused entries
LogPrint(BCLog::NET, "Loaded %d banned node addresses/subnets %dms\n", m_banned.size(),
GetTimeMillis() - n_start);
} else {
LogPrintf("Recreating the banlist database\n");
m_banned = {};
m_is_dirty = true;
}
} looks cleaner to me, fwiw. Just explicitly taking the lock in the constructor seems simpler than delegating to |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
Concept ACK |
Co-authored-by: Anthony Towns <aj@erisian.com.au>
Applied @ajtowns's suggestion which was supported by @w0xlt with 👍 . |
ACK ab75388 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK ab75388
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code-review ACK ab75388
Happy to see that another RecursiveMutex
will bite the dust soon.
…n::SweepBanned()` ab75388 refactor: Remove redundant scope in `BanMan::SweepBanned()` (Hennadii Stepanov) 52c0b3e refactor: Add thread safety annotation to `BanMan::SweepBanned()` (Hennadii Stepanov) 3919059 refactor: Move code from ctor into private `BanMan::LoadBanlist()` (Hennadii Stepanov) Pull request description: This PR adds a proper thread safety annotation to `BanMan::SweepBanned()`. Also a simple refactoring applied. ACKs for top commit: ajtowns: ACK ab75388 w0xlt: ACK bitcoin@ab75388 theStack: Code-review ACK ab75388 Tree-SHA512: 8699079c308454f3ffe72be2e77f0935214156bd509f9338b1104f8d128bfdd02ee06ee8c1c99b2eefdf317a00edd555d52990caaeb1ed4540eedc1e3c9d1faf
This PR adds a proper thread safety annotation to
BanMan::SweepBanned()
.Also a simple refactoring applied.