-
Notifications
You must be signed in to change notification settings - Fork 19
fix(notification): race detected send notification issue #222
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
Conversation
| func (am *AtomicManager) Send(notification interface{}) { | ||
| for _, handler := range am.handlers { | ||
| handlers := am.copyHandlers() | ||
| for _, handler := range handlers { |
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.
instead of copying everything at once, can we just do handler := handler inside the for loop ?
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.
tried didn't work.
pkg/notification/manager.go
Outdated
| @@ -1,5 +1,5 @@ | |||
| /**************************************************************************** | |||
| * Copyright 2019, Optimizely, Inc. and contributors * | |||
| * Copyright 2019-2020, Optimizely, Inc. and contributors * | |||
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.
Haha it's 2020! Still hasn't sunk in yet
pkg/notification/manager.go
Outdated
| for _, handler := range am.handlers { | ||
| handlers := am.copyHandlers() | ||
| for _, handler := range handlers { | ||
| // copying handler to avoid race condition |
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.
Move this comment to right before we copy handlers
mikeproeng37
left a comment
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.
lgtm, just one nit
pkg/notification/manager.go
Outdated
| } | ||
| } | ||
|
|
||
| // Copy handlers and return it. |
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.
nit: Return a copy of the given handlers
mikecdavis
left a comment
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.
Minor comment to copy to a list since we don't need the map interface.
pkg/notification/manager.go
Outdated
| func (am *AtomicManager) copyHandlers() map[uint32]func(interface{}) { | ||
| am.lock.RLock() | ||
| defer am.lock.RUnlock() | ||
| m := make(map[uint32]func(interface{}), len(am.handlers)) | ||
| for k, v := range am.handlers { | ||
| m[k] = v | ||
| } | ||
| return m | ||
| } |
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.
We don't really need a map. We can simply copy to a list.
Summary
TestPlan