-
Notifications
You must be signed in to change notification settings - Fork 63
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
fix/stats race #145
fix/stats race #145
Conversation
37727ce
to
ea854d8
Compare
This needs a DCO sign-off. You can use |
ea854d8
to
4085f6a
Compare
Hmm, should we also protect Maybe we should just migrate these values to Go |
b6ccd59
to
b23432d
Compare
Good catch, added! |
The test currently fails as `PacketsSent` is not protected by `statsMu` in `sendICMP`. Signed-off-by: Per Hallgren <[email protected]>
Writes to the following fields are now protected by `statsMu`: - `ipaddr` - `addr` - `PacketsSent` - `PacketsRecvDuplicates` Signed-off-by: Per Hallgren <[email protected]>
b23432d
to
cb7d28f
Compare
@SuperQ marked as ready for review. Would you like to use atomics instead of the lock? I think both will start to feel a bit ad-hoc, since there's no intuitive boundary what variables are protected by the lock and which ones are just atomic. |
Potentially one could rewrite to use atomics for all variables that we read as a result of a call to |
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 longer term, we should cleanup the whole stats part of the Pinger struct. Maybe make it a separate struct/package with an interface that returns a public value struct.
But, this is a fine enough workaround for now.
PacketsSent
was not protected bystatsMu
when being incremented insendICMP
, which gave a data race when callingStatistics()
on a runningPinger
.This PR adds a small test to test for the data race, and fixes the issue.