Skip to content

Commit

Permalink
threads: avoid deadlock from recursive lock acquire (PR JuliaLang/jul…
Browse files Browse the repository at this point in the history
…ia#38487) (JuliaLang/julia#38753)

Finalizers can't safely acquire many essential locks (such as the
iolock, to cleanup libuv objects) if they are run inside another lock.
Therefore, inhibit all finalizers on the thread until all locks are
released (previously, this was only true for our internal locks).

(cherry-picked from ec8466b)
  • Loading branch information
vtjnash authored Dec 10, 2020
1 parent 8b8590c commit 1253d48
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function flush_gc_msgs(w::Worker)
end

# del_msgs gets populated by finalizers, so be very careful here about ordering of allocations
# XXX: threading requires this to be atomic
new_array = Any[]
msgs = w.del_msgs
w.del_msgs = new_array
Expand Down Expand Up @@ -178,7 +179,7 @@ function send_msg_(w::Worker, header, msg, now::Bool)
wait(w.initialized)
end
io = w.w_stream
lock(io.lock)
lock(io)
try
reset_state(w.w_serializer)
serialize_hdr_raw(io, header)
Expand All @@ -191,7 +192,7 @@ function send_msg_(w::Worker, header, msg, now::Bool)
flush(io)
end
finally
unlock(io.lock)
unlock(io)
end
end

Expand Down

0 comments on commit 1253d48

Please sign in to comment.