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

Seed Libc rng from system entropy #43606

Merged
merged 1 commit into from
Dec 30, 2021
Merged

Seed Libc rng from system entropy #43606

merged 1 commit into from
Dec 30, 2021

Conversation

Keno
Copy link
Member

@Keno Keno commented Dec 30, 2021

We're seeing lots of CI failures that look like collisions in the
names of temporary files. Currently we're seeding the libc
rng from a low entropy clock, which is somewhat likely to have
collisions particular if (as we are), you launch all your processes
at exactly the right time. Try to fix that by seeding the libc using
system entropy. Of course that still leaves the potential for birthday
problems, but hopfully this will tide us over until #43597 gets fixed.

We're seeing lots of CI failures that look like collisions in the
names of temporary variables. Currently we're seeding the libc
rng from a low entropy clock, which is somewhat likely to have
collisions particular if (as we are), you launch all your processes
at exactly the right time. Try to fix that by seeding the libc using
system entropy. Of course that still leaves the potential for birthday
problems, but hopfully this will tide us over until #43597 gets fixed.
@rfourquet rfourquet added the randomness Random number generation and the Random stdlib label Dec 30, 2021
@Keno Keno merged commit 5819775 into master Dec 30, 2021
@Keno Keno deleted the kf/seedlibc branch December 30, 2021 21:26
@DilumAluthge
Copy link
Member

It looks like this has fixed the CI failures! (At least for now.)

Comment on lines 311 to 312
println(stderr,
"Entropy pool not available to seed RNG; using ad-hoc entropy sources.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
println(stderr,
"Entropy pool not available to seed RNG; using ad-hoc entropy sources.")

base = 16) % UInt)
catch
end
Base._ad_hoc_entropy_source()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Base._ad_hoc_entropy_source()
seed = Base._ad_hoc_entropy_source()

end
end # os-test

function _ad_hoc_entropy()
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a unittest for this (just literally call @test_warn "ad-hoc" Base._ad_hoc_entropy_source(), and make sure it returns a reasonable value?

"Entropy pool not available to seed RNG; using ad-hoc entropy sources.")
seed = reinterpret(UInt64, time())
seed = hash(seed, getpid() % UInt)
try
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try
Sys.iswindows() || try

@vtjnash
Copy link
Member

vtjnash commented Jan 7, 2022

There should not be a risk of the birthday paradox anymore, after #38879.

The bigger issue is perhaps actually that rand is of very low quality. Although we try to make it of slightly higher quality (e.,g. filled to 31 bits), this actually may greatly reduce the real quality, as we only use the low bits, but "in fact, the low dozen bits generated by rand go through a cyclic pattern". It also is not thread-safe. Perhaps we should switch to using our cong function (in julia_internal.h)?

LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
We're seeing lots of CI failures that look like collisions in the
names of temporary variables. Currently we're seeding the libc
rng from a low entropy clock, which is somewhat likely to have
collisions particular if (as we are), you launch all your processes
at exactly the right time. Try to fix that by seeding the libc using
system entropy. Of course that still leaves the potential for birthday
problems, but hopfully this will tide us over until JuliaLang#43597 gets fixed.
DilumAluthge added a commit that referenced this pull request Feb 26, 2022
vtjnash added a commit that referenced this pull request Mar 3, 2022
Continuation from #43606

 - Replaces thread-unsafe function `rand` with `jl_rand`.
 - Fixes `_ad_hoc_entropy_source` fallback in Random.
 - Uses uv_random for more direct access to quality-randomness (usually
   a syscall rather than a file.)
 - Ensures Array{Bool} are valid when created from RandomDevice.
vtjnash added a commit that referenced this pull request Mar 8, 2022
Continuation from #43606

 - Replaces thread-unsafe function `rand` with `jl_rand`.
 - Fixes `_ad_hoc_entropy_source` fallback in Random.
 - Uses uv_random for more direct access to quality-randomness (usually
   a syscall rather than a file.)
 - Ensures Array{Bool} are valid when created from RandomDevice.
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
We're seeing lots of CI failures that look like collisions in the
names of temporary variables. Currently we're seeding the libc
rng from a low entropy clock, which is somewhat likely to have
collisions particular if (as we are), you launch all your processes
at exactly the right time. Try to fix that by seeding the libc using
system entropy. Of course that still leaves the potential for birthday
problems, but hopfully this will tide us over until JuliaLang#43597 gets fixed.
vtjnash added a commit that referenced this pull request Mar 8, 2022
Continuation from #43606

 - Replaces thread-unsafe function `rand` with `jl_rand`.
 - Fixes `_ad_hoc_entropy_source` fallback in Random.
 - Uses uv_random for more direct access to quality-randomness (usually
   a syscall rather than a file.)
 - Ensures Array{Bool} are valid when created from RandomDevice.
vtjnash added a commit that referenced this pull request Mar 21, 2022
Continuation from #43606

 - Replaces thread-unsafe function `rand` with `jl_rand`.
 - Fixes `_ad_hoc_entropy_source` fallback in Random.
 - Uses uv_random for more direct access to quality-randomness (usually
   a syscall rather than a file.)
 - Ensures Array{Bool} are valid when created from RandomDevice.
vtjnash added a commit that referenced this pull request Apr 7, 2022
Continuation from #43606

 - Replaces thread-unsafe function `rand` with `jl_rand`.
 - Fixes `_ad_hoc_entropy_source` fallback in Random.
 - Uses uv_random for more direct access to quality-randomness (usually
   a syscall rather than a file.)
 - Ensures Array{Bool} are valid when created from RandomDevice.
KristofferC pushed a commit that referenced this pull request Jul 17, 2022
Continuation from #43606

 - Replaces thread-unsafe function `rand` with `jl_rand`.
 - Fixes `_ad_hoc_entropy_source` fallback in Random.
 - Uses uv_random for more direct access to quality-randomness (usually
   a syscall rather than a file.)
 - Ensures Array{Bool} are valid when created from RandomDevice.

(cherry picked from commit b4bed71)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
randomness Random number generation and the Random stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants