Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

pkg/*: fix data races in PubSub and ticker test #4155

Merged
merged 1 commit into from
Sep 22, 2021

Conversation

shashankram
Copy link
Member

@shashankram shashankram commented Sep 22, 2021

Description:
Fixes a data race in PubSub singleton instantiation
where the singleton object creation is not protected
from concurrent initialization.
Fixes a data race in the ticker test where a variable
is written/read to/from without protected access from
multiple goroutines.

Testing done:
Verified go test -race ./pkg/... succeeds with this change. Previously
the tests would fail on data races in PubSub initialization and ticker test.

Affected area:

Functional Area
Tests [X]

Please answer the following questions with yes/no.

  1. Does this change contain code from or inspired by another project? no

    • Did you notify the maintainers and provide attribution?
  2. Is this a breaking change? no

Fixes a data race in PubSub singleton instantiation
where the singleton object creation is not protected
from concurrent initialization.
Fixes a data race in the ticker test where a variable
is written/read to/from without protected access from
multiple goroutines.

Signed-off-by: Shashank Ram <[email protected]>
@shashankram shashankram requested a review from a team as a code owner September 22, 2021 19:57
@@ -59,8 +64,8 @@ func Unsub(unsubChan chan interface{}) {
// Note that spawning the instance is not thread-safe. First call should happen on
// a single-routine context to avoid races.
func getPubSubInstance() *pubsub.PubSub {
if pubSubInstance == nil {
pubSubOnce.Do(func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@shashankram shashankram merged commit 2d2be96 into openservicemesh:main Sep 22, 2021
@shashankram shashankram deleted the gotest branch September 22, 2021 20:30
snehachhabria pushed a commit to snehachhabria/osm that referenced this pull request Oct 14, 2021
Fixes a data race in PubSub singleton instantiation
where the singleton object creation is not protected
from concurrent initialization.
Fixes a data race in the ticker test where a variable
is written/read to/from without protected access from
multiple goroutines.

Signed-off-by: Shashank Ram <[email protected]>
Signed-off-by: Sneha Chhabria <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants