-
Notifications
You must be signed in to change notification settings - Fork 138
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
CBG-4108 acquire lock to prevent NewWaiter data race #7012
Conversation
db/change_listener.go
Outdated
@@ -308,7 +309,7 @@ func (listener *changeListener) NewWaiter(keys []string, trackUnusedSequences bo | |||
listener: listener, | |||
keys: keys, | |||
lastCounter: listener.CurrentCount(keys), | |||
lastTerminateCheckCounter: listener.terminateCheckCounter, | |||
lastTerminateCheckCounter: listener.terminateCheckCounter.Load(), |
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.
I think your PR comment suggests that that using listener.L.Lock to safely fetch the value of terminateCheckCounter here will deadlock. Can you clarify why that's the case, or what the issue of that approach is? It would be preferable to avoid acquiring two locks in changeListener.Wait, since that's used highly concurrently.
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.
I misanalysed the situation but it was caught in tests. I pushed an update that removes atomic and just acquires the lock once for NewWaiter
instead of once for listener._currentCount
and listener.terminateCheckCounter
.
As far as I could tell, everywhere else we already acquire the lock on read or write of listener._terminateCheckCounter
.
The lock was already used for listener.CurrentCount(keys), so mark _terminateCheckCounter as needing a lock as well.
* CBG-4108 use an atomic to avoid data race * Grab one lock in NewWaiter The lock was already used for listener.CurrentCount(keys), so mark _terminateCheckCounter as needing a lock as well. * Avoid double lock on NewWaiterWithChannels
I can not actually reproduce the data race with high -count -race.