-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: fix a possible race between Flow.Cleanup and Flow.Cancel #95522
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
Release note: None
5f338a4
to
d525206
Compare
This commit fixes a possible race that could occur when `Flow.Cleanup` is called by the main goroutine concurrently with `Flow.Cancel` by the listener goroutine (which is not allowed). We already had synchronization in place, but it was insufficient. In particular, the following scenario could lead to a nil pointer crash: - the listener checks whether `Cleanup` has been called, it hasn't, and the mutex is unlocked; - the listener is preemptied; - the main goroutine proceeds to perform the `Cleanup`. At the very end the flow object is unset (including `ctxCancel` overwritten to `nil`); - the listener resumes its execution, proceeds to call `Cancel` on the already-unset `Flow` object, leading to a nil pointer on `ctxCancel` call. This is now fixed by holding the mutex through the call to `Cancel` in the listener goroutine, ensuring that the `Flow` object is not unset from under the listener. Additionally, this commit clarifies the callbacks that are performed at the very beginning and very end of `Cleanup` method. Release note: None
d525206
to
23da047
Compare
I added another commit that fixes another (although less frequent) race. RFAL. |
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.
Reviewed 1 of 1 files at r1, 5 of 5 files at r2, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @andreimatei)
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.
Reviewable status: complete! 2 of 0 LGTMs obtained (waiting on @yuzefovich)
TFTRs! bors r+ |
Build succeeded: |
This commit fixes a possible race that could occur when
Flow.Cleanup
is called by the main goroutine concurrently with
Flow.Cancel
by thelistener goroutine (which is not allowed). We already had
synchronization in place, but it was insufficient. In particular, the
following scenario could lead to a nil pointer crash:
Cleanup
has been called, it hasn't, andthe mutex is unlocked;
Cleanup
. At the very endthe flow object is unset (including
ctxCancel
overwritten tonil
);Cancel
on thealready-unset
Flow
object, leading to a nil pointer onctxCancel
call.
This is now fixed by holding the mutex through the call to
Cancel
inthe listener goroutine, ensuring that the
Flow
object is not unsetfrom under the listener. Additionally, this commit clarifies the
callbacks that are performed at the very beginning and very end of
Cleanup
method.Fixes: #95527.
Release note: None