Skip to content

Commit 6272995

Browse files
andreasnoackDilumAluthge
authored andcommitted
Ensure correct type parameter of serialized RemoteChannel (#179)
When serializing RemoteChannels, a new zeroed RemoteChannel is constructed. However, the input type parameter might be part of an outer type parameter which can then lead to a TypeError during deserialization. The fix is just to reuse the type parameter of the input when constructing the zeroed RemoteChannel. (cherry picked from commit 6649a94075ff6a52ee9558db3ec4491496bf1bea)
1 parent fbca46f commit 6272995

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/remotecall.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ function serialize(s::AbstractSerializer, ::Future)
413413
invoke(serialize, Tuple{AbstractSerializer, Any}, s, zero_fut)
414414
end
415415

416-
function serialize(s::AbstractSerializer, ::RemoteChannel)
417-
zero_rc = RemoteChannel{Channel{Any}}((0,0,0))
416+
function serialize(s::AbstractSerializer, ::RemoteChannel{T}) where T
417+
zero_rc = RemoteChannel{T}((0,0,0))
418418
invoke(serialize, Tuple{AbstractSerializer, Any}, s, zero_rc)
419419
end
420420

test/distributed_exec.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,12 @@ end
343343
@testset "Ser/deser to non-ClusterSerializer objects" begin
344344
function test_regular_io_ser(ref::DistributedNext.AbstractRemoteRef)
345345
io = IOBuffer()
346-
serialize(io, ref)
346+
# Wrapping the ref in a Dict to exercise the case when the
347+
# type parameter of the RemoteChannel is part of an outer type.
348+
# See https://github.com/JuliaLang/Distributed.jl/issues/178
349+
serialize(io, Dict("ref" => ref))
347350
seekstart(io)
348-
ref2 = deserialize(io)
351+
ref2 = deserialize(io)["ref"]
349352
for fld in fieldnames(typeof(ref))
350353
v = getfield(ref2, fld)
351354
if isa(v, Number)
@@ -361,6 +364,7 @@ end
361364

362365
test_regular_io_ser(Future())
363366
test_regular_io_ser(RemoteChannel())
367+
test_regular_io_ser(RemoteChannel(() -> Channel{Bool}(1)))
364368
end
365369

366370
@testset "@distributed and [un]buffered reads" begin

0 commit comments

Comments
 (0)