Search code examples
akkaactorakka-supervision

What happens to messages sent to an actor while it is suspended?


Here is the situation, One my actors (A) is supervised by a Backoff supervisor (B).

The sequence of events that interest me is the following:

  1. The system starts and everybody is happy
  2. A fails while processing a message
  3. B now considers A to be suspended until the backoff delay elapses
  4. B receives some messages (MM) that he is meant to forward to A
  5. The backoff delay elaspes and B restarts A
  6. Everybody is happy again

On step 4, what happens to those messages?

Are they lost? Sent to dead-letters? stashed inside B somewhere, and sent to A when it restarts / resumes?

Now let's add another layer: A is not a standard Actor but an Actor with Stash.

What happens to the stash of messages between the failure of A and its restart/resume? Is it discarded? Is it unstashed? Is it kept inside the stash?


Solution

  • After a few experiments, I think I can answer both of my questions above:

    What happens to messages sent to an actor supervised by a Backoff supervisor between the moment the actor fails and the moment it is restarted?

    They are sent to deadLetters()

    What happens to the stash of messages between the failure of an actor and its restart?

    Nothing happens to the stash until the restart is actually attempted. When the restarting process starts, the preRestart() step of the stash calls unstashAll() to return all messages to the mailbox. Therefore messages are not lost, and not kept in the stash, but just unstashed and returned to the mailbox.