Ocassional precompile error on a cluster using julia1.8

I’ve just started using julia 1.8 on a cluster, and I have faced the following error while instantiating (or adding packages to) an environment:

┌ Error: Pkg.precompile error
│   exception =
│    IOError: could not spawn `/scratch/user/julia/julia-1.8/bin/julia -Cnative -J/scratch/user/julia/julia-1.8/lib/julia/sys.so -g1 -O0 --output-ji /scratch/user/.julia/compiled/v1.8/IterTools/jl_CVGiTl --output-incremental=yes --startup-file=no --history-file=no --warn-overwrite=yes --color=yes -`: resource temporarily unavailable (EAGAIN)
│    Stacktrace:
│      [1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Union{RawFD, IO}})
│        @ Base ./process.jl:128
│      [2] #725
│        @ ./process.jl:139 [inlined]
│      [3] setup_stdios(f::Base.var"#725#726"{Cmd}, stdios::Vector{Union{RawFD, IO}})
│        @ Base ./process.jl:223
│      [4] _spawn
│        @ ./process.jl:138 [inlined]
│      [5] _spawn(::Base.CmdRedirect, ::Vector{Union{RawFD, IO}}) (repeats 2 times)
│        @ Base ./process.jl:166
│      [6] open(cmds::Base.CmdRedirect, stdio::Base.TTY; write::Bool, read::Bool)
│        @ Base ./process.jl:397
│      [7] open(cmds::Base.CmdRedirect, mode::String, stdio::Base.TTY)
│        @ Base ./process.jl:366
│      [8] create_expr_cache(pkg::Base.PkgId, input::String, output::String, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, internal_stderr::IO, internal_stdout::IO)
│        @ Base ./loading.jl:1443
│      [9] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, ignore_loaded_modules::Bool)
│        @ Base ./loading.jl:1524
│     [10] (::Pkg.API.var"#245#274"{IOBuffer, String, Base.PkgId})()
│        @ Pkg.API /scratch/user/julia/julia-1.8/share/julia/stdlib/v1.8/Pkg/src/API.jl:1310
│     [11] with_logstate(f::Function, logstate::Any)
│        @ Base.CoreLogging ./logging.jl:511
│     [12] with_logger
│        @ ./logging.jl:623 [inlined]
│     [13] macro expansion
│        @ /scratch/user/julia/julia-1.8/share/julia/stdlib/v1.8/Pkg/src/API.jl:1308 [inlined]
│     [14] (::Pkg.API.var"#242#271"{Bool, Pkg.Types.Context, Vector{Task}, Pkg.API.var"#handle_interrupt#263"{Base.Event, ReentrantLock, Base.TTY}, Pkg.API.var"#color_string#261", Base.Event, Base.Event, ReentrantLock, Vector{Base.PkgId}, Vector{Base.PkgId}, Dict{Base.PkgId, String}, Vector{Base.PkgId}, Vector{Base.PkgId}, Vector{Pkg.Types.PackageSpec}, Dict{Base.PkgId, Bool}, Dict{Base.PkgId, Base.Event}, Dict{Base.PkgId, Bool}, Vector{Base.PkgId}, Bool, Base.TTY, Base.Semaphore, String, Vector{String}, Vector{Base.PkgId}, Base.PkgId})()
│        @ Pkg.API ./task.jl:482
└ @ Pkg.API /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.8/Pkg/src/API.jl:1183

I’m not sure what this issue is about, and I don’t face it on my laptop. Any help?

I’ve had some luck by following Limit how many threads used during precompile · Issue #2404 · JuliaLang/Pkg.jl · GitHub and setting ENV["JULIA_NUM_PRECOMPILE_TASKS"] to a low number (eg 4).