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
Replace RecursiveMutex m_cs_banned with Mutex, and rename it #24097
Conversation
ef12449
to
39e101f
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
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.
tACK 39e101f
In addition to the refactoring, this PR:
. Adds lock acquisition in BanMan::DumpBanlist
before calling SweepBanned()
.
. Replaces BanMan::SetBannedSetDirty()
with WITH_LOCK(m_cs_banned, m_is_dirty = false);
(write operation) or simply m_is_dirty
(non-blocking read operation).
. SweepBanned()
no longer locks the mutex, just checks that it is held. This function is now called with WITH_LOCK(m_banned_mutex, SweepBanned());
.
. BanMan::DumpBanlist
called BanMan::SweepBanned()
twice (directly and via BanMan::GetBanned
). Now it gets rid of BanMan::GetBanned
and handles banmap_t banmap
within the lock scope.
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 39e101f
I prefer that the SweepBanned function, instead of locking m_cs_banned
by itself, now asserts it being locked by its caller function. This prevents any need for double locking, and hence m_cs_banned
could be safely converted from RecursiveMutex to Mutex.
The renaming of m_cs_banned
to m_banned_mutex
is an improvement, and I agree with it.
The conversion of m_banned_mutex
from RecursiveMutex to Mutex is very cleanly implemented and is clutter-free.
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 39e101f.
There is a behavior change where m_client_interface->BannedListChanged()
is now called with the lock held. The only place that connects to that signal is in ClientModel
where updateBanlist
is called asynchronously, so I'd say this change is deadlock-free.
The same behavior is on the master branch: Lines 160 to 166 in d0bf9bb
isn't it? |
@hebasto right! Only checked that from |
…pBanlist()` 99a6b69 Fix race condition for SetBannedSetDirty() calls (Hennadii Stepanov) 83c7646 Avoid calling BanMan::SweepBanned() twice in a row (Hennadii Stepanov) 33bda6a Fix data race condition in BanMan::DumpBanlist() (Hennadii Stepanov) 5e20e9e Prevent possible concurrent CBanDB::Write() calls (Hennadii Stepanov) Pull request description: This PR split from bitcoin/bitcoin#24097 with some additions. This makes the following switch from `RecursiveMutex` to `Mutex` a pure refactoring. See details in commit messages. ACKs for top commit: w0xlt: reACK 99a6b69 shaavan: ACK 99a6b69 Tree-SHA512: da4e7268c7bd3424491f446145f18af4ccfc804023d0a7fe70e1462baab550a5e44f9159f8b9f9c7820d2c6cb6447b63883616199e4d9d439ab9ab1b67c7201b
39e101f
to
0ad0288
Compare
Rebased 39e101f -> 0ad0288 (pr24097.02 -> pr24097.03) on top of the merged #24168. |
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
I had a nit suggestion and a doubt that I would like to discuss.
99a6b69 Fix race condition for SetBannedSetDirty() calls (Hennadii Stepanov) 83c7646 Avoid calling BanMan::SweepBanned() twice in a row (Hennadii Stepanov) 33bda6a Fix data race condition in BanMan::DumpBanlist() (Hennadii Stepanov) 5e20e9e Prevent possible concurrent CBanDB::Write() calls (Hennadii Stepanov) Pull request description: This PR split from bitcoin#24097 with some additions. This makes the following switch from `RecursiveMutex` to `Mutex` a pure refactoring. See details in commit messages. ACKs for top commit: w0xlt: reACK 99a6b69 shaavan: ACK 99a6b69 Tree-SHA512: da4e7268c7bd3424491f446145f18af4ccfc804023d0a7fe70e1462baab550a5e44f9159f8b9f9c7820d2c6cb6447b63883616199e4d9d439ab9ab1b67c7201b
Converted to draft for now. Please review #25149 first. |
@maflcko Mind having a look at this PR please? |
ACK 37d150d 🎾 Show signatureSignature:
|
ACK 37d150d |
99a6b69 Fix race condition for SetBannedSetDirty() calls (Hennadii Stepanov) 83c7646 Avoid calling BanMan::SweepBanned() twice in a row (Hennadii Stepanov) 33bda6a Fix data race condition in BanMan::DumpBanlist() (Hennadii Stepanov) 5e20e9e Prevent possible concurrent CBanDB::Write() calls (Hennadii Stepanov) Pull request description: This PR split from bitcoin#24097 with some additions. This makes the following switch from `RecursiveMutex` to `Mutex` a pure refactoring. See details in commit messages. ACKs for top commit: w0xlt: reACK 99a6b69 shaavan: ACK 99a6b69 Tree-SHA512: da4e7268c7bd3424491f446145f18af4ccfc804023d0a7fe70e1462baab550a5e44f9159f8b9f9c7820d2c6cb6447b63883616199e4d9d439ab9ab1b67c7201b
99a6b69 Fix race condition for SetBannedSetDirty() calls (Hennadii Stepanov) 83c7646 Avoid calling BanMan::SweepBanned() twice in a row (Hennadii Stepanov) 33bda6a Fix data race condition in BanMan::DumpBanlist() (Hennadii Stepanov) 5e20e9e Prevent possible concurrent CBanDB::Write() calls (Hennadii Stepanov) Pull request description: This PR split from bitcoin#24097 with some additions. This makes the following switch from `RecursiveMutex` to `Mutex` a pure refactoring. See details in commit messages. ACKs for top commit: w0xlt: reACK 99a6b69 shaavan: ACK 99a6b69 Tree-SHA512: da4e7268c7bd3424491f446145f18af4ccfc804023d0a7fe70e1462baab550a5e44f9159f8b9f9c7820d2c6cb6447b63883616199e4d9d439ab9ab1b67c7201b
99a6b69 Fix race condition for SetBannedSetDirty() calls (Hennadii Stepanov) 83c7646 Avoid calling BanMan::SweepBanned() twice in a row (Hennadii Stepanov) 33bda6a Fix data race condition in BanMan::DumpBanlist() (Hennadii Stepanov) 5e20e9e Prevent possible concurrent CBanDB::Write() calls (Hennadii Stepanov) Pull request description: This PR split from bitcoin#24097 with some additions. This makes the following switch from `RecursiveMutex` to `Mutex` a pure refactoring. See details in commit messages. ACKs for top commit: w0xlt: reACK 99a6b69 shaavan: ACK 99a6b69 Tree-SHA512: da4e7268c7bd3424491f446145f18af4ccfc804023d0a7fe70e1462baab550a5e44f9159f8b9f9c7820d2c6cb6447b63883616199e4d9d439ab9ab1b67c7201b
This PR is an alternative to #24092. Last two commit have been cherry-picked from the latter.