liveBook · Manning

Behaviors.failed

As explained in Akka in Action, Second Edition

Behaviors.failed is an Akka Typed factory for a failed actor behavior that stops message processing until the actor is restarted or terminated.

Behaviors.failed marks an actor as failed after an exception. The actor stops processing mailbox messages while supervision either terminates it or prepares a replacement incarnation. section 5.3.2 section 5.3.3

Failure followed by termination

An actor processes message X and raises an exception. The supervisor selects Behaviors.failed, so no further mailbox messages are processed. The actor then receives PostStop, allowing cleanup of open connections, files, or other expiring resources, before its mailbox, supervisor, and actor are removed. section 5.3.2

The failed state participates in two supervision paths:

  • Stop: transition from Behaviors.failed to Behavior.stopped, process PostStop, and permanently remove the actor. section 5.3.2
  • Restart: set Behaviors.failed, deliver PreRestart, stop the faulty incarnation, and create a new actor with the same ActorRef. section 5.3.3
  • Restart preserves the communication facade but loses ordinary actor state; persistent actors are required for state retention in harder failure scenarios. section 5.3.3
  • Use restartWithBackoff when an external service may remain unavailable, increasing retry delays between a configured minimum and maximum. section 5.3.3
Figure 5.8 An actor with a default supervision strategy is stopped.
CH05_F08_Abraham2

Trace the default supervision path from a failed message through Behaviors.failed, PostStop, and final actor termination. section 5.3.2

Figure 5.9 Actor with a restart supervision strategy
CH05_F09_Abraham2

Compare the restart lifecycle: failure, PreRestart, removal of the old incarnation, and creation of its replacement. section 5.3.3

How Akka in Action, Second Edition covers it

How deep it goes
Explains stop and restart lifecycles, cleanup signals, state loss, and backoff, but not persistent-actor implementation.
Examples
Uses failed-message lifecycle diagrams, PostStop cleanup code, stop supervision configuration, and restart supervision scenarios.
What it assumes
Assumes Akka Typed behaviors and actor supervision while introducing PostStop and PreRestart signal handling.
What you can do after
Operate/configure supervised actors that stop, restart, clean up, or back off after failures.
How it connects
Connects Behaviors.failed with supervision strategies, Behavior.stopped, PostStop, PreRestart, ActorRef, 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.