Aplakka File: Supervision Strategies not working in Directory.walk(path)

(Vito Jeng) #1


I use Directory.walk(path) to traverse all subdirectories.
It works perfectly.
But some subdirectories may encounter permission issue and throw an exception:

java.io.UncheckedIOException: java.nio.file.AccessDeniedException: /full/path/name

I want to use supervision strategies(resume) so that the stream can continue the process.
But it seems with no luck. Follow is the sample code:

    val decider: Supervision.Decider = {
      case _: UncheckedIOException => Supervision.Resume
      case _                      => Supervision.Stop

    implicit val actorSystem = ActorSystem("FileIOExample")
    val actorMaterializerSettings = ActorMaterializerSettings(actorSystem).withSupervisionStrategy(decider)
    implicit val actorMaterializer = ActorMaterializer(actorMaterializerSettings)
    implicit val ec = actorSystem.dispatcher

    Directory.walk(Paths.get("/")).to {
      Sink.foreach(f =>

Do I miss something? Thanks a lot.

(Ivano Pagano) #2

Supervision in akka-streams is trickier than in Actors
If you look at the note at the paragraph beginning, you’ll discover that each stage might or might not support supervision.

The point is that you need to check out if the Directory.walk stage is one of the “lucky guys”, and read the docs to learn if and how it might handle supervision

(Enno) #3

Hi @Ivano

Thank you for your question and investigation about Directory.walk. You’re right that operator doesn’t have supervision built in right now.

It is a very thin wrapper of Files.walk so you might want to take a copy to experiment with add supervision.

It would be great if you would come up with a Pull Request to improve it in Alpakka!


(Ivano Pagano) #4

Well maybe @vitojeng will be more interested into that, I was just giving a hint to the current situation.

I currently have no time to dedicate, sadly.

(Vito Jeng) #5

Thank you @Ivano, very helpful!
I would take a look when I have time.

Also thanks @ennru for the explanation.