Skip to content

Commit 3cc4ce2

Browse files
committed
Prevent TOCTTOU race in finalize_ref
1 parent 5118a1b commit 3cc4ce2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

stdlib/Distributed/src/remotecall.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ 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+
delete!(client_refs.ht, r) # HACK: prevent TOCTTOU pattern
89+
unlock(client_refs)
90+
else
8891
# delay finalizer for later, when it's not already locked
8992
finalizer(finalize_ref, r)
9093
return nothing
9194
end
92-
delete!(client_refs, r)
9395
if isa(r, RemoteChannel)
9496
send_del_client(r)
9597
else

0 commit comments

Comments
 (0)