-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add before you push to the queue to prevent race condition on size #2044
Add before you push to the queue to prevent race condition on size #2044
Conversation
|
Signed-off-by: Joe Elliott <[email protected]>
4942e9d
to
6aaa413
Compare
Codecov Report
@@ Coverage Diff @@
## master #2044 +/- ##
==========================================
- Coverage 97.4% 97.39% -0.01%
==========================================
Files 207 207
Lines 10315 10286 -29
==========================================
- Hits 10047 10018 -29
Misses 224 224
Partials 44 44
Continue to review full report at Codecov.
|
@@ -105,12 +105,13 @@ func (q *BoundedQueue) Produce(item interface{}) bool { | |||
return false | |||
} | |||
|
|||
q.size.Add(1) |
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.
This actually looks like a real bug, we are subtracting in both code branches, but adding in only one. Good catch!
Thanks for the PR! |
Which problem is this PR solving?
Fixes #2042
Short description of the changes
Adding to size before we put an item in the channel prevents
q.size.Sub(1)
hitting before the addition. This prevents the uint from underflowing to max value.This change fixed the issue described in #2042 in our environment.
cc @gouthamve