Skip to content

Commit 945048e

Browse files
committed
Prevent TOCTTOU race in finalize_ref
1 parent 5118a1b commit 945048e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

stdlib/Distributed/src/remotecall.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,17 @@ end
8484

8585
function finalize_ref(r::AbstractRemoteRef)
8686
if r.where > 0 # Handle the case of the finalizer having been called manually
87-
if islocked(client_refs)
87+
if trylock(client_refs)
88+
try
89+
delete!(client_refs.ht, r) # HACK: prevent TOCTTOU pattern
90+
finally
91+
unlock(client_refs)
92+
end
93+
else
8894
# delay finalizer for later, when it's not already locked
8995
finalizer(finalize_ref, r)
9096
return nothing
9197
end
92-
delete!(client_refs, r)
9398
if isa(r, RemoteChannel)
9499
send_del_client(r)
95100
else

0 commit comments

Comments
 (0)