Skip to content

Commit

Permalink
threads: avoid deadlock from recursive lock acquire
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
vtjnash committed Dec 3, 2020
1 parent b186a31 commit ec8466b
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 @@ -135,6 +135,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 @@ -166,7 +167,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 @@ -179,7 +180,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 ec8466b

Please sign in to comment.