-
Notifications
You must be signed in to change notification settings - Fork 525
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 concurrent map write panic in monitoring middleware #14335
Fix concurrent map write panic in monitoring middleware #14335
Conversation
This pull request does not have a backport label. Could you fix it @carsonip? 🙏
|
|
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 this could be a good candidate for sync Map, wdyt ? (Since the counter should only be written once but read many times)
I didn't benchmark. But you should be right as stated in sync.Map docs:
|
With this bench: package syncmap
import (
"sync"
"testing"
)
func BenchmarkSyncMap(b *testing.B) {
m := sync.Map{}
m.LoadOrStore("foo", "bar")
b.RunParallel(func(p *testing.PB) {
for p.Next() {
m.Load("foo")
}
})
}
func BenchmarkRWMutex(b *testing.B) {
rw := sync.RWMutex{}
m := map[string]string{"foo": "bar"}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
rw.RLock()
_ = m["foo"]
rw.RUnlock()
}
})
} Result:
|
Fix panic due to monitoring middleware concurrent map write. (cherry picked from commit 5cd8b7d)
) Fix panic due to monitoring middleware concurrent map write. (cherry picked from commit 5cd8b7d) Co-authored-by: Carson Ip <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Motivation/summary
Fix panic due to monitoring middleware concurrent map write.
Alternative to this, we could have populated the maps with all the possible keys, but we may risk missing some possible map keys.
Checklist
For functional changes, consider:
How to test these changes
Related issues