AssertionError: 0 < tid <= length(THREAD_RNGs) when generating a random number
I see this is a recurring issue that was "sort of" fixed before: https://discourse.julialang.org/t/assertionerror-0-tid-length-thread-rngs-during-compilation-with-packagecompiler/69179
However, I'm getting spotty results at best. I recently tried to precompile a new docker image for project I wrote in May 2021. When precompiling a project using Julia v1.6.5 and PackageCompiler v1.2.5 (the version that was active at the time) the project compiles.
When using some newer packages, it frequently fails. In the discourse above, it appears someone created a fix for this in version 1.7.0. When compiling with PackageCompiler v1.7.0 it "successfully" compiles, but then when deploying, the docker image produces a segfault. Apparantly, this segfault issue was fixed with v1.7.2 when looking at the patch notes, but every version after this fails in the same way as the most recent version.
For the current version compiling with PackageCompiler v2.0.5 it fails with the following message (which I believe is due to generating a random number using Distributions.jl). Is there something about generating random numbers that is not allowed?
AssertionError: 0 < tid <= length(THREAD_RNGs) Stacktrace: [1] _rng_length_assert() @ Random /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Random/src/RNGs.jl:381 [2] default_rng(tid::Int64) @ Random /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Random/src/RNGs.jl:372 [3] default_rng @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Random/src/RNGs.jl:370 [inlined] [4] rand @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Random/src/RNGs.jl:413 [inlined] [5] rand @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Random/src/Random.jl:253 [inlined] [6] rand @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Random/src/generation.jl:35 [inlined] [7] rand (repeats 2 times) @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Random/src/Random.jl:256 [inlined] [8] rand @ ~/.julia/packages/Distributions/O4ZJg/src/univariates.jl:157 [inlined] [9] _rand!(rng::Random._GLOBAL_RNG, sampler::Distributions.Truncated{Distributions.Gamma{Float64}, Distributions.Continuous, Float64}, A::Vector{Float64}) @ Distributions ~/.julia/packages/Distributions/O4ZJg/src/univariates.jl:147 [10] rand! @ ~/.julia/packages/Distributions/O4ZJg/src/univariates.jl:142 [inlined] [11] rand @ ~/.julia/packages/Distributions/O4ZJg/src/genericrand.jl:52 [inlined] [12] rand @ ~/.julia/packages/Distributions/O4ZJg/src/genericrand.jl:24 [inlined] [13] rand @ ~/.julia/packages/Distributions/O4ZJg/src/genericrand.jl:22 [inlined]
I am also getting this error when trying to compile a sysimage with PackageCompiler 2.0.6 but TiffImages is the offending package (as in the Discourse post).
What Julia version are you using?
I am still on 1.6.5.
Okay, hm, I can probably hack around it to fix it for v1.6. I think this should be fixed on 1.7+.
It seems like removing the plotting libraries (Makie, Plots, etc) from the prjoect also fixes it.
So I ran into some other (most likely) unrelated compilation issues and ended up nuking my .julia folder, re-instantiating the entire project environment, and now PackageCompiler works again, even with the plotting packages. So I guess it's a Heisenbug?