liveBook · Manning

PreRestart

As explained in Akka in Action, Second Edition

PreRestart is an Akka Typed lifecycle signal delivered to an actor before the actor is removed for restart.

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

Figure 5.9 Actor with a restart supervision strategy
CH05_F09_Abraham2

Trace the failure, PreRestart notification, removal, and reinitialization sequence in the restart supervision flow. section 5.3.3

How Akka in Action, Second Edition covers it

How deep it goes
Explains signal timing, failed behavior, recreation, message stashing, and state loss, while deferring durable recovery to persistent actors.
Examples
Uses an exception-triggered restart, an IndexOutOfBoundException supervision configuration, and restartWithBackoff for external failures.
What it assumes
Assumes actor protocols and spawning, while distinguishing signals from messages and introducing supervision-driven lifecycle handling.
What you can do after
Operate/configure restart supervision and reason about cleanup timing, message continuity, reinitialization, and lost volatile state.
How it connects
Connects PreRestart with supervision strategies, PostStop, Behavior.setup, ActorRef, watching, and persistent actors.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.