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

   #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

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
  [1] getindex
    @ ./array.jl:924 [inlined]
  [2] getindex
    @ ./abstractarray.jl:1244 [inlined]
  [3] desertag
    @ /Applications/ [inlined]
  [4] handle_deserialize
    @ /Applications/
  [5] deserialize
    @ /Applications/
  [6] handle_deserialize
    @ /Applications/
  [7] deserialize
    @ /Applications/
  [8] handle_deserialize
    @ /Applications/
  [9] deserialize
    @ /Applications/ [inlined]
 [10] deserialize_msg
    @ /Applications/
 [11] #invokelatest#2
    @ ./essentials.jl:729 [inlined]
 [12] invokelatest
    @ ./essentials.jl:726 [inlined]
 [13] message_handler_loop
    @ /Applications/
 [14] process_tcp_streams
    @ /Applications/
 [15] #103
    @ ./task.jl:484
  [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/
  [8] pmap
    @ /Applications/ [inlined]
  [9] #pmap#233
    @ /Applications/ [inlined]
 [10] pmap
    @ /Applications/ [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.