Open jonas-schulze opened 1 year ago
This is similar to #35177 and #35673, but the example task shown there fails before having produced any elements. This failure is detected or propagated as expected.
Furthermore, it is a bit tricky to write a test for this, as the behavior seems to change when using for _ in c end
over foreach(_ -> (), c)
and whether this is nested in a @test_throws
or @testset
.
# mwe2.jl
using Test
c0() = Channel(_ -> error("foo"))
c1() = Channel() do ch
put!(ch, 42)
error("foo")
end
noop(_) = nothing
@testset "Channel Task Failures" begin
@test_throws TaskFailedException for _ in c0() end
@test_throws TaskFailedException for _ in c1() end
@test_throws TaskFailedException foreach(println, c0())
@test_throws TaskFailedException foreach(println, c1()) # only one that breaks
@test_throws TaskFailedException foreach(noop, c1())
end
There seems to be a race condition, at least in the case of failure before the first element. This swallows the error:
c = Channel() do ch
error("foo")
end
sleep(0.001)
iterate(c) # returns `nothing`
and when removing the sleep
, the error propagates nested in a TaskFailedException
(as in Julia 1.7).
There is also a regression in the case of close(channel, exception)
. This swallows the error on 1.8 and 1.9:
s = Channel() do ch
close(ch, ErrorException("foo"))
end
iterate(s)
julia> versioninfo()
Julia Version 1.9.0
Commit 8e630552924 (2023-05-07 11:25 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × AMD Ryzen 3 3100 4-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, znver2)
Threads: 1 on 8 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =
If the function passed to the channel ctor fails after having produced some elements, the exception raised is being lost. This is a regression starting in Julia 1.8. I tested Julia versions 1.6.7, 1.7.3, 1.8.5, and 1.9.3.
Expected behavior: