Skip to content

Commit ec8466b

Browse files
committed
threads: avoid deadlock from recursive lock acquire
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).
1 parent b186a31 commit ec8466b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/messages.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function flush_gc_msgs(w::Worker)
135135
end
136136

137137
# del_msgs gets populated by finalizers, so be very careful here about ordering of allocations
138+
# XXX: threading requires this to be atomic
138139
new_array = Any[]
139140
msgs = w.del_msgs
140141
w.del_msgs = new_array
@@ -166,7 +167,7 @@ function send_msg_(w::Worker, header, msg, now::Bool)
166167
wait(w.initialized)
167168
end
168169
io = w.w_stream
169-
lock(io.lock)
170+
lock(io)
170171
try
171172
reset_state(w.w_serializer)
172173
serialize_hdr_raw(io, header)
@@ -179,7 +180,7 @@ function send_msg_(w::Worker, header, msg, now::Bool)
179180
flush(io)
180181
end
181182
finally
182-
unlock(io.lock)
183+
unlock(io)
183184
end
184185
end
185186

0 commit comments

Comments
 (0)