Skip to content

Commit 8d1970e

Browse files
committed
don't corrupt the identity of AbstractRemoteRef in their finalizers
this made it unreliable for the WeakKeyDict these are typically put in (client_refs) to have trouble finding them to cleanup the dictionary later since their hash and identity changed fixes #15923 reverts workaround #14456 (doesn't break #14295 due to previous commit) may also fix #16091
1 parent feaf59f commit 8d1970e

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

base/multi.jl

+12-21
Original file line numberDiff line numberDiff line change
@@ -493,15 +493,13 @@ type Future <: AbstractRemoteRef
493493
v::Nullable{Any}
494494

495495
Future(w::Int, rrid::RRID) = Future(w, rrid, Nullable{Any}())
496-
Future(w::Int, rrid::RRID, v) = (r = new(w,rrid.whence,rrid.id,v); test_existing_ref(r))
496+
Future(w::Int, rrid::RRID, v) = (r = new(w,rrid.whence,rrid.id,v); return test_existing_ref(r))
497497
end
498498

499499
function finalize_future(f::Future)
500500
if f.where > 0
501501
isnull(f.v) && send_del_client(f)
502502
f.where = 0
503-
f.whence = 0
504-
f.id = 0
505503
f.v = Nullable{Any}()
506504
end
507505
f
@@ -512,7 +510,7 @@ type RemoteChannel{T<:AbstractChannel} <: AbstractRemoteRef
512510
whence::Int
513511
id::Int
514512

515-
RemoteChannel(w::Int, rrid::RRID) = (r = new(w, rrid.whence, rrid.id); test_existing_ref(r))
513+
RemoteChannel(w::Int, rrid::RRID) = (r = new(w, rrid.whence, rrid.id); return test_existing_ref(r))
516514
end
517515

518516
function test_existing_ref(r::Future)
@@ -527,25 +525,23 @@ function test_existing_ref(r::Future)
527525
end
528526
client_refs[r] = true
529527
finalizer(r, finalize_future)
530-
r
528+
return r
531529
end
532530

533531
function test_existing_ref(r::RemoteChannel)
534532
found = getkey(client_refs, r, false)
535533
!is(found,false) && (client_refs[r] == true) && return found
536534
client_refs[r] = true
537535
finalizer(r, finalize_remote_channel)
538-
r
536+
return r
539537
end
540538

541539
function finalize_remote_channel(r::RemoteChannel)
542540
if r.where > 0
543541
send_del_client(r)
544542
r.where = 0
545-
r.whence = 0
546-
r.id = 0
547543
end
548-
r
544+
return r
549545
end
550546

551547
Future(w::LocalProcess) = Future(w.id)
@@ -614,18 +610,13 @@ end
614610

615611
del_client(id, client) = del_client(PGRP, id, client)
616612
function del_client(pg, id, client)
617-
# As a workaround to issue https://github.com/JuliaLang/julia/issues/14445
618-
# the dict/set updates are executed asynchronously so that they do
619-
# not occur in the midst of a gc. The `@async` prefix must be removed once
620-
# 14445 is fixed.
621-
@async begin
622-
rv = get(pg.refs, id, false)
623-
if rv != false
624-
delete!(rv.clientset, client)
625-
if isempty(rv.clientset)
626-
delete!(pg.refs, id)
627-
#print("$(myid()) collected $id\n")
628-
end
613+
rv = get(pg.refs, id, false)
614+
615+
if rv != false
616+
delete!(rv.clientset, client)
617+
if isempty(rv.clientset)
618+
delete!(pg.refs, id)
619+
#print("$(myid()) collected $id\n")
629620
end
630621
end
631622
nothing

0 commit comments

Comments
 (0)