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

Use math/rand global random source and deprecate PRNG global variable #13

Merged
merged 1 commit into from
Mar 2, 2024

Conversation

justinrixx
Copy link
Contributor

closes #12

Copy link
Member

@mna mna left a comment

Choose a reason for hiding this comment

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

Thanks, looks good! Just a couple comments that should be addressed before merging.

rehttp.go Outdated
PRNG.Int63n(int64(math.Min(float64(max), top))),
rand.Int63n(int64(math.Min(float64(max), top))),
)
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's have this function call ExpJitterDelayWithRand and pass rand.Int63n as the generator function, so that the algorithm is implemented only in one place.

rng_pre120.go Outdated
// Only seed the global random source on versions prior to 1.20 since
// it's pre-seeded starting in 1.20
func init() {
rand.Seed(time.Now().UnixNano())
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the package should do this - the caller might have seeded the global source with a known value to get deterministic results. I think we should document on ExpJitterDelay that it assumes the global source has been properly seeded by the caller.

@justinrixx
Copy link
Contributor Author

All valid feedback. I should have recognized the duplication in ExpJitterDelayWithRand.

Updated now and ready for re-review.

Copy link
Member

@mna mna left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mna mna merged commit e90a5fa into PuerkitoBio:master Mar 2, 2024
6 checks passed
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.

rand.Rand is not safe for concurrent use
2 participants