-
Notifications
You must be signed in to change notification settings - Fork 443
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 mutex around rng *rand.Rand to avoid data race on resume #156
Conversation
@@ -1004,6 +1009,8 @@ func (r *Consumer) redistributeRDY() { | |||
availableMaxInFlight = 1 - atomic.LoadInt64(&r.totalRdyCount) | |||
} | |||
|
|||
r.rngMtx.Lock() | |||
defer r.rngMtx.Unlock() |
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.
can we reduce the size of this critical path and put this lock around just the call to r.rng.Int()
?
thanks for this, just one minor comment! |
I've addressed the comment. |
LGTM, do you mind squashing down to one commit? |
@@ -106,7 +106,8 @@ type Consumer struct { | |||
channel string | |||
config Config | |||
|
|||
rng *rand.Rand | |||
rngMtx sync.RWMutex |
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.
RWMutex
is designed for separate read and write locks. Since we only want global locking can you use sync.Mutex
here?
Squashed and changed to using sync.Mutex. |
Add mutex around rng *rand.Rand to avoid data race on resume
Currently there is a data race when a consumer hits a backoff condition and then resumes. The resume via time.AfterFunc gets called from a different goroutine.
Note: this could also have been solved using one of the existing mutexes (r.mtx or r.backoffMtx).