-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Version Information
Version of Akka.NET? Latest dev branch
Which Akka.NET Modules? Akka.Stream
Describe the bug
Related code:
akka.net/src/core/Akka.Streams/Implementation/Fusing/Ops.cs
Lines 2591 to 2592 in 61bdebf
| 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 itsResult<T>.Exceptionproperty 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 anArgumentException. - 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