-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Guard fHavePruned
to avoid potential data race
#22212
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
Guard fHavePruned
to avoid potential data race
#22212
Conversation
9591794
to
b20925d
Compare
A potential data race has been detected on `fHavePruned` where one thread is writing to it via `FlushStateToDisk` as another thread is reading it via `IsBlockPruned`.
b20925d
to
2402883
Compare
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. |
Looks ok, just two notes:
|
Go from using `cs_main` to `cs_HavePruned` as a mutex for accessing `fHavePruned`. This so as to not block the validation thread with blockstorage related RPCs.
Thanks for the feedback @MarcoFalke |
@@ -1476,6 +1477,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) | |||
|
|||
try { | |||
LOCK(cs_main); | |||
LOCK(cs_HavePruned); |
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.
Unsure whether to lock the whole block or line 1485 specifically
My reasoning here was that verifying blocks ought to have higher priority than answering RPC requests
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
As detailed in #21627, there is a potential data race on
fHavePruned
as one thread could be reading it while another one is writing to it.Guard
fHavePruned
, lock inIsBlockPruned
(FlushStateToDisk
is holdingcs_main
while writing to the variable, so this ensures that the data race cannot occur).