Skip to content

Conversation

@msohailhussain
Copy link
Contributor

@msohailhussain msohailhussain commented Jan 2, 2020

Summary

TestPlan

  • Added unit tests for race detected scenarios.

func (am *AtomicManager) Send(notification interface{}) {
for _, handler := range am.handlers {
handlers := am.copyHandlers()
for _, handler := range handlers {
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried didn't work.

@msohailhussain msohailhussain marked this pull request as ready for review January 2, 2020 21:23
@msohailhussain msohailhussain requested a review from a team as a code owner January 2, 2020 21:23
@mikeproeng37 mikeproeng37 requested a review from mjc1283 January 3, 2020 00:06
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2019, Optimizely, Inc. and contributors *
* Copyright 2019-2020, Optimizely, Inc. and contributors *
Copy link
Contributor

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

for _, handler := range am.handlers {
handlers := am.copyHandlers()
for _, handler := range handlers {
// copying handler to avoid race condition
Copy link
Contributor

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

Copy link
Contributor

@mikeproeng37 mikeproeng37 left a 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

}
}

// Copy handlers and return it.
Copy link
Contributor

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

Copy link
Contributor

@mikecdavis mikecdavis left a 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.

Comment on lines 85 to 93
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
}
Copy link
Contributor

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.

@mikeproeng37 mikeproeng37 merged commit 11e8e84 into master Jan 3, 2020
@mikeproeng37 mikeproeng37 deleted the sohail/racefix branch January 3, 2020 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants