Skip to content

Stream upstream error propagation can fail in async calls #7432

@Arkatufus

Description

@Arkatufus

Version Information
Version of Akka.NET? Latest dev branch
Which Akka.NET Modules? Akka.Stream

Describe the bug

Related code:

task.ContinueWith(t => holder.Invoke(Result.FromTask(t)),
TaskContinuationOptions.ExecuteSynchronously);

A bug in Result<T>.FromTask() where it failed to check for an edge case where a Task can be in a cancelled state but have its Task.Exception property be null. In fact, TaskCancelledException would only be thrown if Task.Result was called.

  • This causes an event where Result<T> is in a failed state with its Result<T>.Exception property null.
  • This in turn is picked up by the upstream error propagation and
  • the null exception is passed upstream and was caught by the OutGraphStageLogic.OnDownstreamFinish() method, causing it to throw an ArgumentException.
  • This causes the whole stream to shutdown immediately without completing the proper graceful shutdown logic

Any code listening to the stream completion will never receive the completion signal.
This can be the root cause of why Akka.Streams.Kafka fails, because the parent stream could not pick up the death of its sub-stream

To Reproduce
Steps to reproduce the behavior:

var tcs = new TaskCompletionSource<int>();
tcs.TrySetCanceled();

var result = Result.FromTask(tcs.Task);
result.IsSuccess.Should().BeFalse();
result.Exception.Should().NotBeNull(); // Fails

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions