Restarting children and loss of messages

My user supervisor actor creates child actors C1 and C2 ; C1 is supervisor to C11 ; C2 is supervisor to C21.

  • now, if C1 throws an error, supervisor would restart C1. From below code and akka doc, it appears that C1 will stop C11. Due to C1 restart, its messages are not lost. However, will C11 messages be lost as its stopped?

  • C2 will be restarted due to sibling error and hence not lose its messages. However, it appears C21 will be stopped and lose its messages.

Is my above understanding correct? My above statements are based on the below code in Actor trait:

def preRestart(reason: Throwable, message: Option[Any]): Unit = {
  context.children foreach { child ⇒
    context.unwatch(child)
    context.stop(child)
  }
  postStop()
}

It’s correct that child actors are by default stopped when parent actor is restarted. That is the safest option and it assumes that the parent will create new child actors (e.g. from its constructor).

You can change that behavior to keep the children by overriding preRestart of the parent.

C2 and sibling error isn’t correct unless you use AllForOne strategy.