From 2e529965ef354af6c7ad19f8dac3d5374cf0a804 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Wed, 18 Feb 2026 23:45:26 +0100 Subject: [PATCH] Ensure correct type parameter of serialized RemoteChannel (#179) This is a forward-port of https://github.com/JuliaLang/Distributed.jl/pull/179 (https://github.com/JuliaLang/Distributed.jl/commit/6649a94075ff6a52ee9558db3ec4491496bf1bea). 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) --- src/remotecall.jl | 4 ++-- test/distributed_exec.jl | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/remotecall.jl b/src/remotecall.jl index 644ff04..6abd821 100644 --- a/src/remotecall.jl +++ b/src/remotecall.jl @@ -413,8 +413,8 @@ function serialize(s::AbstractSerializer, ::Future) invoke(serialize, Tuple{AbstractSerializer, Any}, s, zero_fut) end -function serialize(s::AbstractSerializer, ::RemoteChannel) - zero_rc = RemoteChannel{Channel{Any}}((0,0,0)) +function serialize(s::AbstractSerializer, ::RemoteChannel{T}) where T + zero_rc = RemoteChannel{T}((0,0,0)) invoke(serialize, Tuple{AbstractSerializer, Any}, s, zero_rc) end diff --git a/test/distributed_exec.jl b/test/distributed_exec.jl index a218bf6..19d10eb 100644 --- a/test/distributed_exec.jl +++ b/test/distributed_exec.jl @@ -343,9 +343,12 @@ end @testset "Ser/deser to non-ClusterSerializer objects" begin function test_regular_io_ser(ref::DistributedNext.AbstractRemoteRef) io = IOBuffer() - serialize(io, ref) + # Wrapping the ref in a Dict to exercise the case when the + # type parameter of the RemoteChannel is part of an outer type. + # See https://github.com/JuliaLang/Distributed.jl/issues/178 + serialize(io, Dict("ref" => ref)) seekstart(io) - ref2 = deserialize(io) + ref2 = deserialize(io)["ref"] for fld in fieldnames(typeof(ref)) v = getfield(ref2, fld) if isa(v, Number) @@ -361,6 +364,7 @@ end test_regular_io_ser(Future()) test_regular_io_ser(RemoteChannel()) + test_regular_io_ser(RemoteChannel(() -> Channel{Bool}(1))) end @testset "@distributed and [un]buffered reads" begin