-
Notifications
You must be signed in to change notification settings - Fork 325
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 race condition #34 #42
Conversation
@klizhentas can you help me with this PR? |
@@ -138,6 +148,10 @@ func (m *RTMetrics) Append(other *RTMetrics) error { | |||
return err | |||
} | |||
|
|||
m.statusCodesLock.Lock() |
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 there's a potential deadlock here:
a.Append(b)
and
b.Append(a)
will deadlock.
To mitigate the issue, I would suggest to do the following:
- implement Export function that uses RLock and returns the copy of the map with status codes
- in append, do this:
copied := other.Export()
m.Lock()
defer m.Unlock()
do the merge....
return
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.
Good catch! I'll update this.
done, sorry for the delay. two notes:
Thanks |
Hi @klizhentas, sorry for the delay I was busy with some other work. I've update the PR for the two points you've mentioned. Let me know if I missed anything. Happy to make changes. |
any news on this PR? |
Fix race condition #34