Skip to content
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 worker random race condition #179

Merged
merged 1 commit into from Jan 28, 2021
Merged

Conversation

hush-hush
Copy link
Member

rand.NewSource is not thread safe. Each worker needs its own random and random-lock.

Copy link
Member

@olivielpeau olivielpeau left a comment

Choose a reason for hiding this comment

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

Not a blocker, I'm just curious: what's the impact of this change on the benchmark of the original PR: #178 ?

statsd/worker.go Outdated Show resolved Hide resolved
Copy link

@ogaca-dd ogaca-dd left a comment

Choose a reason for hiding this comment

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

LGTM

statsd/worker.go Show resolved Hide resolved
@@ -71,9 +73,15 @@ func (w *worker) processMetric(m metric) error {
}

func (w *worker) shouldSample(rate float64) bool {
// rand.NewSource is not thread safe.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: for clarity, I suggest:

Suggested change
// rand.NewSource is not thread safe.
// sources created by rand.NewSource() (ie. w.random) are not thread safe.

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.

None yet

4 participants