-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
pkg/rand: replace SafeRand by global source in math/rand #29731
Conversation
94e5f12
to
3a58712
Compare
b973bf5
to
e44b450
Compare
Since Go 1.20 the top-level math/rand functions are auto-seeded by default, see https://go.dev/doc/go1.20#library and golang/go#54880. They also use the runtime's lock-free fastrand64 function when 1. Seed has not been called and 2. GODEBUG=randautoseed=0 is not used, see golang/go#49892. This allows to drop SafeRand and use the global source again. SafeRand was originally introduced in commit fac5dde ("rand: add and use concurrency-safe PRNG source") to fix #10988 by providing a concurrency-safe PRNG source other than the global math/rand source which could be used at the time because it can't be interfered with from unrelated packages by means of calling rand.Seed, see #10575. rand.Seed is deprecated since Go 1.20 and per the paragraph above the global source is seeded by default. This makes it unlikely that packages would interfere with the global PRNG state anymore and the top-level math/rand functions are safe to use again. Signed-off-by: Tobias Klauser <tobias@cilium.io>
e44b450
to
7b25186
Compare
/test |
If I understand correctly, how can we ensure that some packages we import don't call
which we call from here cilium/pkg/health/server/prober.go Line 382 in 52c06e1
|
Good point. I guess we could use some kind of checker akin to That doesn't sound like a really feasible approach though. I think instead we should wait for the |
This pull request has been automatically marked as stale because it |
Superseded by #32542 |
Since Go 1.20 the top-level math/rand functions are auto-seeded by default, see https://go.dev/doc/go1.20#library and golang/go#54880. They also use the runtime's lock-free fastrand64 function when 1. Seed has not been called and 2.
GODEBUG=randautoseed=0
is not used, see golang/go#49892.This allows to drop
SafeRand
and use the global source again.SafeRand
was originally introduced in commit fac5dde ("rand: add and use concurrency-safe PRNG source") to fix #10988 by providing a concurrency-safe PRNG source other than the globalmath/rand
source which couldn't be used at the time because it can be interfered with from unrelated packages by means of callingrand.Seed
, see #10575.rand.Seed
is deprecated since Go 1.20 and per the paragraph above the global source is seeded by default. This makes it unlikely that packages would interfere with the global PRNG state anymore and the top-levelmath/rand
functions are safe to use again.