-
Notifications
You must be signed in to change notification settings - Fork 2.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
nsqd: fix lack of synchronization around ChannelStats #971
Conversation
Ah, I see - we can't "atomically" get the |
nsqd/stats.go
Outdated
c.inFlightMutex.Lock() | ||
defer c.inFlightMutex.Unlock() | ||
c.deferredMutex.Lock() | ||
defer c.deferredMutex.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.
Let's tighten up the critical sections between these locks and move the len(...)
reads from out of the struct instantiation to temp variables here?
Awesome. Can you squash down to one commit? |
Your test did seem to expose a remaining data race in go-1.7:
Is it just in the test itself possibly? I may have time to take a look later. (I manually triggered a re-test and it passed :P) |
Ah, OK, obviously you need to call |
My bad. I didn't even think about the fact that copying the map is actually a reference to the map. So using a local copy puts you right back to where you started, with the actual map object being accessed from outside the lock. Fix up in a few minutes. |
* create inFlightMessages and deferredMessages maps inside mutex. * acquire appropriate mutexes before doing len() in NewChannelStats() * add test that checks for passing -race when accessing stats while serving messages. Fixes issue #970.
Okay, fix is up, and commits squashed. |
thanks! |
serving messages.
Fixes issue #970.