-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
kvserver: prevent recursive Replica.mu.RLock #97381
Conversation
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.
Commit message would be helpful:
Previously, we were passing an RLocked
*Replica
to(*Store).addToReplicasByKeyLocked
. That method internally visits the descriptors and calledDesc()
, which would constitute a recursive call toRLock
(caught by the deadlock detector due to the risk of a deadlock in case of an interleaving exclusive lock attempt to the mutex). <explain here how it can happen that while inserting a replica we're visiting the same replica? Was this a split? Or just a test doing funky things?>
Previously, we were passing an RLocked Replica to addToReplicasByKeyLocked. That method internally visits the descriptors in replicasByKey, which calls Desc() that may cause a recursive call to RLock if the added replica intersects itself. This is only possible in tests which try to reinsert the Replica to the map; in prod code each Replica is inserted to replicasByKey only once. Release note: none Epic: none
064f42c
to
a908137
Compare
@tbg Could you take another look? The previous version of this PR was deadlock-full. I fixed the deadlock at the cost of some duplication: the caller now passes the replica's |
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.
👍🏽
also 😬 at this locking in general
bors r=tbg |
bors cancel |
Canceled. |
bors r=tbg |
Build succeeded: |
Previously, we were passing an RLocked Replica to addToReplicasByKeyLocked.
That method internally visits the descriptors in replicasByKey, which calls
Desc() that may cause a recursive call to RLock if the added replica intersects
itself. This is only possible in tests which try to reinsert the Replica to the
map; in prod code each Replica is inserted to replicasByKey only once.
This PR avoids the possibility of this deadlock by shifting the responsibility
of locking to the caller.
Fixes #96931
Release note: none
Epic: none