Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #40337, no error info from serialized TaskFailedException #40395

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ end
function show_task_exception(io::IO, t::Task; indent = true)
stack = catch_stack(t)
b = IOBuffer()
show_exception_stack(IOContext(b, io), stack)
if isempty(stack)
# exception stack buffer not available; probably a serialized task
showerror(IOContext(b, io), t.result)
else
show_exception_stack(IOContext(b, io), stack)
end
str = String(take!(b))
if indent
str = replace(str, "\n" => "\n ")
Expand Down
24 changes: 0 additions & 24 deletions stdlib/Distributed/src/clusterserialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,6 @@ function serialize(s::ClusterSerializer, t::Core.TypeName)
nothing
end

function serialize(s::ClusterSerializer, t::Task)
serialize_cycle(s, t) && return
if istaskstarted(t) && !istaskdone(t)
error("cannot serialize a running Task")
end
writetag(s.io, TASK_TAG)
serialize(s, t.code)
serialize(s, t.storage)
serialize(s, t._state)
serialize(s, t.result)
serialize(s, t._isexception)
end

function serialize(s::ClusterSerializer, g::GlobalRef)
# Record if required and then invoke the default GlobalRef serializer.
sym = g.name
Expand Down Expand Up @@ -244,17 +231,6 @@ function deserialize(s::ClusterSerializer, t::Type{<:CapturedException})
return CapturedException(capex, bt)
end

function deserialize(s::ClusterSerializer, ::Type{Task})
t = Task(nothing)
deserialize_cycle(s, t)
t.code = deserialize(s)
t.storage = deserialize(s)
t._state = deserialize(s)::UInt8
t.result = deserialize(s)
t._isexception = deserialize(s)
t
end

"""
clear!(syms, pids=workers(); mod=Main)

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ let e = @test_throws RemoteException pmap(1) do _
es = sprint(showerror, e.value)
@test contains(es, ":\nTaskFailedException\nStacktrace:\n")
@test contains(es, "\n\n nested task error:")
@test_broken contains(es, "\n\n nested task error: 42\n")
@test contains(es, "\n\n nested task error: 42\n")
end

# issue #27429, propagate relative `include` path to workers
Expand Down
14 changes: 11 additions & 3 deletions stdlib/Serialization/src/Serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,19 @@ function serialize(s::AbstractSerializer, t::Task)
if istaskstarted(t) && !istaskdone(t)
error("cannot serialize a running Task")
end
state = [t.code, t.storage, t.state, t.result, t._isexception]
writetag(s.io, TASK_TAG)
for fld in state
serialize(s, fld)
serialize(s, t.code)
serialize(s, t.storage)
serialize(s, t.state)
if t._isexception && (stk = Base.catch_stack(t); !isempty(stk))
# the exception stack field is hidden inside the task, so if there
# is any information there make a CapturedException from it instead.
# TODO: Handle full exception chain, not just the first one.
serialize(s, CapturedException(stk[1][1], stk[1][2]))
else
serialize(s, t.result)
end
serialize(s, t._isexception)
end

function serialize(s::AbstractSerializer, g::GlobalRef)
Expand Down