Skip to content

Commit 1253d48

Browse files
authored
threads: avoid deadlock from recursive lock acquire (PR JuliaLang/julia#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)
1 parent 8b8590c commit 1253d48

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
@@ -147,6 +147,7 @@ function flush_gc_msgs(w::Worker)
147147
end
148148

149149
# del_msgs gets populated by finalizers, so be very careful here about ordering of allocations
150+
# XXX: threading requires this to be atomic
150151
new_array = Any[]
151152
msgs = w.del_msgs
152153
w.del_msgs = new_array
@@ -178,7 +179,7 @@ function send_msg_(w::Worker, header, msg, now::Bool)
178179
wait(w.initialized)
179180
end
180181
io = w.w_stream
181-
lock(io.lock)
182+
lock(io)
182183
try
183184
reset_state(w.w_serializer)
184185
serialize_hdr_raw(io, header)
@@ -191,7 +192,7 @@ function send_msg_(w::Worker, header, msg, now::Bool)
191192
flush(io)
192193
end
193194
finally
194-
unlock(io.lock)
195+
unlock(io)
195196
end
196197
end
197198

0 commit comments

Comments
 (0)