ActorSystem.shutdown, and actor termination

1,362 views
Skip to first unread message

dle...@mdialog.com

unread,
Jun 27, 2013, 3:14:55 PM6/27/13
to akka...@googlegroups.com
Hi,

I'm wondering if the behaviour I'm seeing is expected ; when shutting down an actor system with actorA supervising its child actorB, actorA does not receive a Terminated message. 
It seems like it should according to the documentation :

Termination of an actor proceeds in two steps: first the actor suspends its mailbox processing and sends a stop command to all its children, then it keeps processing the termination messages from its children until the last one is gone, finally terminating itself (invoking postStop, dumping mailbox, publishing Terminated on the DeathWatch, telling its supervisor). This procedure ensures that actor system sub-trees terminate in an orderly fashion, propagating the stop command to the leaves and collecting their confirmation back to the stopped supervisor. If one of the actors does not respond (i.e. processing a message for extended periods of time and therefore not receiving the stop command), this whole process will be stuck.


Here is an example (akka 2.2-RC1) :

scala> val system = ActorSystem("system")system: akka.actor.ActorSystem = akka://system

scala> class ActorB extends Actor { def receive ={ case _ =>} ; override def postStop() { println("postStop B") } }defined class ActorB

scala> class ActorA extends Actor { val actorB = context.actorOf(Props[ActorB]) ; context.watch(actorB) ; def receive = { case Terminated(actor) => println("supervised terminated :"+ actor) } ; override def postStop() { println("postStop A") } }
defined class ActorA

scala> val actorA = system.actorOf(Props(classOf[ActorA]))actorA: akka.actor.ActorRef = Actor[akka://system/user/$a#-1326401100]

scala> system.registerOnTermination(println("System shutdown"))
scala> system.shutdown()
scala> postStop B
postStop A
System shutdown

I'll be happy to have some clarification on that behaviour. 

Thanks

Damien 

√iktor Ҡlang

unread,
Jun 27, 2013, 7:02:18 PM6/27/13
to Akka User List
Spontaneous guess: A is terminated before it can process the Terminated message. Did you check what ends up in DeadLetters?

Cheers,


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Viktor Klang
Director of Engineering

Twitter: @viktorklang

Patrik Nordwall

unread,
Jun 28, 2013, 2:53:55 AM6/28/13
to akka...@googlegroups.com
When you shutdown the actor system it will stop the root actor, which will stop children down the tree. stop of an actor means that it will not process any more messages after current message, so there is no chance for the parent to process the Terminated message, since the stopping of it has already begun. An implementation detail is that it will actually unwatch all watched actors to avoid exactly these dead letters (so you will not see them there).

If you need this for some reason I think you should implement your own, application specific, stopping traversal. You might get inspiration from this pattern: http://letitcrash.com/post/29773618510/an-akka-2-terminator

/Patrik

Patrik Nordwall
Typesafe The software stack for applications that scale
Twitter: @patriknw

anorwell

unread,
Jun 28, 2013, 11:49:40 AM6/28/13
to akka...@googlegroups.com
Hi,

Can you clarify what this sentence from the documentation means:

Termination of an actor proceeds in two steps: first the actor suspends its mailbox processing and sends a stop command to all its children, then it keeps processing the termination messages from its children until the last one is gone, finally terminating itself (invoking postStop, dumping mailbox, publishing Terminated on the DeathWatch, telling its supervisor). 

Is this incorrect? How does an actor process the termination messages from its children, other than through receiving Terminated messages in its mailbox? 

√iktor Ҡlang

unread,
Jun 28, 2013, 12:00:28 PM6/28/13
to Akka User List


Hi!

On Fri, Jun 28, 2013 at 5:49 PM, anorwell <anor...@mdialog.com> wrote:
Hi,

Can you clarify what this sentence from the documentation means:

Termination of an actor proceeds in two steps: first the actor suspends its mailbox processing and sends a stop command to all its children, then it keeps processing the termination messages from its children until the last one is gone, finally terminating itself (invoking postStop, dumping mailbox, publishing Terminated on the DeathWatch, telling its supervisor). 

Is this incorrect? How does an actor process the termination messages from its children, other than through receiving Terminated messages in its mailbox? 

Terminated is a user-level message received as a consequence of using Death Watch. Supervision is using system-level messages that are not visible to user code and jump the user-level mailbox.

"publishing Terminated on the DeathWatch, telling its supervisor" <-- does not mean that the Terminated message is used to tell its supervisor. These steps are separate, hence the comma :-)

Cheers,

dle...@mdialog.com

unread,
Jul 2, 2013, 1:24:27 PM7/2/13
to akka...@googlegroups.com
Thanks for the clarification, I got confused by the following sentence, and assumed the supervisor would always processed Terminated messages.

it keeps processing the termination messages from its children until the last one is gone


Regards

Damien

√iktor Ҡlang

unread,
Jul 2, 2013, 2:10:49 PM7/2/13
to Akka User List
You're most welcome!

Happy hAkking

Cheers,

Akka Team

unread,
Jul 5, 2013, 2:18:32 PM7/5/13
to Akka User List
A small clarification is under way: https://github.com/akka/akka/pull/1603

Regards,

Roland
Akka Team
Typesafe - The software stack for applications that scale
Blog: letitcrash.com
Twitter: @akkateam

√iktor Ҡlang

unread,
Jul 5, 2013, 2:37:38 PM7/5/13
to Akka User List
Looks good, nice work Roland!
Reply all
Reply to author
Forward
0 new messages