Error handling in RestartSink.withBackoff

Hi everyone,

I’m using RestartSink.withBackoff to recover from a sink failures (in my case a MongoSink). Everything works well, when there is an exception while persisting to the db the stream does not fail and the sink restarts. However, I don’t get any logs from the failure. Is there a way to react to the exception that happen in the internal sink (MongoSink), so one can log them and also ensure that db connections are properly terminated?

Just to exemplify with code:

someSource
    .log("mongo-recorder")
    .to(RestartSink.withBackoff[...](backoffSettings)(
        () => MongoSink.insertOne(mongoCollection) // if this dies, stream goes on, but nothing is logged
    )
3 Likes

The RestartSettings has a logSettings where you should be able to set the log level for restarts. The default should be to log at warning though (akka/RestartSettings.scala at d703a2afe0e0c6dc8f1c0321b0f4652600e2ae99 · akka/akka · GitHub), so perhaps something isn’t working as it should in the RestartSink.

Please report as a bug in the Akka tracker if you can confirm no logging with default config in a minimal repeater (just a simple failing sink not the mongo one, for example something like Sink.foreach(n => if (n > 2) throw new RuntimeException())).