akka.net icon indicating copy to clipboard operation
akka.net copied to clipboard

Akka Stream AlsoTo may not be failing graph when its sink throws exception

Open richardjharding opened this issue 8 months ago • 0 comments

Version Information Version of Akka.NET? 1.5.25 Which Akka.NET Modules? Akka.Streams 1.5.25

Describe the bug A simple graph with source, sink and an intermediate AlsoTo stage with its own sink, if the sink referenced by the AlsoTo flow throws an exception the rest of the graph completes instead of failing the complete graph

To Reproduce

The following console app I think demonstrates the issue

// See https://aka.ms/new-console-template for more information
using Akka.Actor;
using Akka.Streams;
using Akka.Streams.Dsl;

Console.WriteLine("Starting Akka Stream");

var system = ActorSystem.Create("MySystem");
var materializer = system.Materializer();

var source = Source.From(Enumerable.Range(1, 100));

var sink = Sink.ForEach<int>(i => Console.WriteLine($"Main sink {i}"));

var alsoSink = Sink.ForEach<int>(i => throw new Exception("sink failed") );


var alsoFlow = Flow.Create<int>()
                .WireTap(i => Console.WriteLine($"also wiretap: {i}"))
                .To(alsoSink);

var task = source
           .AlsoTo(alsoFlow)           
           .ToMaterialized(sink, Keep.Right).Run(materializer);

await task;


Links to working reproductions on Github / Gitlab are very much appreciated

Expected behavior

When the AlsoTo flow fails the complete graph should fail

Actual behavior No further output is seen from the AlsoTo stage but the other sink continues to receive elements

Environment

Windows 11, Dotnet 8

Additional context

I first noticed this when working with alpakka where the AlsoTo stream sink was an Azure Service bus queue, the main flow reading from an Azure Event Hub and it continued to emit elements even after the service bus sink threw an exception

Note no exception is returned by the failed AlsoTo stage in my Azure example the actor starting the stream has the task piped back to itself - and no fail message is received

richardjharding avatar Jun 27 '24 15:06 richardjharding