PreRestart is an Akka Typed lifecycle signal delivered before a failed actor is removed for restart. It belongs to the actor’s signal handling rather than its ordinary command or request protocol. section 5.2 section 5.3.3
A restart proceeds through these observable stages:
- A message raises an exception, and the supervisor selects the restart strategy. section 5.3.3
- The actor switches to Behavior.failed, preventing further message processing while the system sends PreRestart. section 5.3.3
- The faulty incarnation is stopped and a new incarnation of the same actor definition is spawned and reinitialized. section 5.3.3
- The ActorRef remains valid, while messages sent during the transition are stashed and later processed by the replacement. section 5.3.3
Supervising a restart
A restart supervision strategy can be attached with Behaviors.supervise(behavior).onFailure[IndexOutOfBoundException](SupervisorStrategy.restart). Handle PreRestart when cleanup or failure-time coordination is needed, but do not expect ordinary actor state to survive: standard actor state is lost during recreation. For failures caused by an external HTTP server or database, restartWithBackoff can increase the waiting period between attempts. section 5.3.3
Trace the failure, PreRestart notification, removal, and reinitialization sequence in the restart supervision flow. section 5.3.3
