Weird UndefRefError in pmap since 1.8

Hey. I am kind of new to the language and my coding knowledge is very minimal. Therefore I am unable to solve (even understand) the problem I have right now.

My code is kind of large and convoluted and I don’t know how to really extract a minimal example. I cannot even reproduce the error in the full code reliably.

I use something like this in my code:

function fill_arr1!(arr1::Array,parameter::Float64,d::Int64,L::Int64)

    #allocate buffers
    arr2=zeros(d)
    arr3=zeros(d)

   #execute routines with pmap
   result1=pmap( idx -> routine1(idx, parameter,arr2,arr3), 1:L)
   result2=pmap( idx -> routine2(idx, parameter,arr2,arr3), 1:L)

   return result1,result2
end

This function is part of a deq-solver and is used once per step. Sometimes the whole code works without error and sometimes at some random iteration step I get the following error (I omitted the last line which basically says that the error happens in the function I tried to paraphrase above):

ERROR: On worker 2:
UndefRefError: access to undefined reference
Stacktrace:
  [1] getindex
    @ ./array.jl:924 [inlined]
  [2] getindex
    @ ./abstractarray.jl:1244 [inlined]
  [3] desertag
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Serialization/src/Serialization.jl:100 [inlined]
  [4] handle_deserialize
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Serialization/src/Serialization.jl:851
  [5] deserialize
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Serialization/src/Serialization.jl:1479
  [6] handle_deserialize
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Serialization/src/Serialization.jl:877
  [7] deserialize
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Serialization/src/Serialization.jl:1479
  [8] handle_deserialize
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Serialization/src/Serialization.jl:877
  [9] deserialize
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Serialization/src/Serialization.jl:813 [inlined]
 [10] deserialize_msg
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Distributed/src/messages.jl:87
 [11] #invokelatest#2
    @ ./essentials.jl:729 [inlined]
 [12] invokelatest
    @ ./essentials.jl:726 [inlined]
 [13] message_handler_loop
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Distributed/src/process_messages.jl:176
 [14] process_tcp_streams
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Distributed/src/process_messages.jl:133
 [15] #103
    @ ./task.jl:484
Stacktrace:
  [1] (::Base.var"#939#941")(x::Task)
    @ Base ./asyncmap.jl:177
  [2] foreach(f::Base.var"#939#941", itr::Vector{Any})
    @ Base ./abstractarray.jl:2774
  [3] maptwice(wrapped_f::Function, chnl::Channel{Any}, worker_tasks::Vector{Any}, c::UnitRange{Int64})
    @ Base ./asyncmap.jl:177
  [4] wrap_n_exec_twice
    @ ./asyncmap.jl:153 [inlined]
  [5] #async_usemap#924
    @ ./asyncmap.jl:103 [inlined]
  [6] #asyncmap#923
    @ ./asyncmap.jl:81 [inlined]
  [7] pmap(f::Function, p::WorkerPool, c::UnitRange{Int64}; distributed::Bool, batch_size::Int64, on_error::Nothing, retry_delays::Vector{Any}, retry_check::Nothing)
    @ Distributed /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Distributed/src/pmap.jl:126
  [8] pmap
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Distributed/src/pmap.jl:99 [inlined]
  [9] #pmap#233
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Distributed/src/pmap.jl:156 [inlined]
 [10] pmap
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Distributed/src/pmap.jl:156 [inlined]

Sorry, cannot make it more concrete than this. Anyway: on my old machine with windows and Julia 1.7. this worked out flawlessly. Now I am working with a new machine (MacBook) and Julia 1.8. and getting this error sometimes.

For someone with little experience this error message is really hard to comprehend, but I figure that some of the inputs in the anonymous functions include something like an undef value, but I simply cannot locate this behavior in the code. Also that the code ran perfectly well before makes me believe that this actually has to do something with the newer Julia version and not with my code. Strangely, when I replace the two pmaps with just simple loops over all desired indices, the code also works without an error.