awaitTermination not working?

197 views
Skip to first unread message

Eduardo Fernandes

unread,
Mar 9, 2016, 3:47:43 PM3/9/16
to Akka User List
Hi group! Thanks for your time in advance.

I'm using Java version 2.3.13. In my JUnit tests and when I'm testing in single node the awaitTermination function after the traditional shutdown() is not awaiting for the actor system termination. In fact the actorsystem is not event starting to shutdown.

I found this and this but I didn't found a clear solution to my problem. For other tests in multi-node environment the awaiting function is working fine.

Any idea?

Many thanks again for your help.

/Eduardo




Akka Team

unread,
Mar 11, 2016, 7:14:42 AM3/11/16
to Akka User List
Hi Eduardo,

If you have an actor that is blocking indefinitely, the actor system termination will never complete, could this be the case? If it is you should be able to see that by getting a thread dump from the JVM and see one of your actor blocking one of the dispatcher threads.

--
Johan Andrén
Akka Team, Lightbend Inc.

Eduardo Fernandes

unread,
Mar 11, 2016, 7:23:05 AM3/11/16
to akka...@googlegroups.com
Hi. 

Hum... I think that is not the case. In fact the methods shutdown() and awaitTermination() simply don't block at all and the next test says that the port 12551 is already bound. If my previous test starts two nodes everything works find and the awaitTermination() method waits for the node shutdown.

The problem only appears when my test is single node.

Thanks for your time.

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/tkCnKcjj1tI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Patrik Nordwall

unread,
Mar 11, 2016, 7:33:33 AM3/11/16
to akka...@googlegroups.com
You must use shutdown followed by awaitTermination.
(note that awaitTermination is replaced by something else in 2.4.x, see deprecation)

In TestKit there is a helper method to shutdown the actor system, await and verify.

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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--

Patrik Nordwall
Akka Tech Lead
Lightbend -  Reactive apps on the JVM
Twitter: @patriknw

 Lightbend

Eduardo Fernandes

unread,
Mar 11, 2016, 7:39:45 AM3/11/16
to akka...@googlegroups.com
Hi. Thanks Patrik.

I am using shutdown() and then awaitTermination(). Both don't block and return immediately. My previous test start two nodes and the the awaitTermination() blocks as expected and everything works fine. The only test which fails is the one which works in single-node mode. 

I've tried the TestKit and the behavior is exactly the same.

In other words, if I start a new node in the same test the function blocks as expected. 

Thanks again.

Patrik Nordwall

unread,
Mar 11, 2016, 7:43:16 AM3/11/16
to akka...@googlegroups.com
Please share minimized code of the problem. We use this all over the place so I'm pretty sure your code is not correct.

Eduardo Fernandes

unread,
Mar 11, 2016, 7:45:59 AM3/11/16
to akka...@googlegroups.com
Me too :(

I'l prepare a minimum example. Typically when I do this the problem get clear and I could fix my test code :)

Regards.
 

Eduardo Fernandes

unread,
Mar 13, 2016, 8:23:23 PM3/13/16
to Akka User List
Hum... it's look like an actor which uses an asynchronous DB persistor from an external library sometimes launches a thread. When the thread is running the shutdown() does nothing and the awaitTermination() doesn't block. If I stop the thread (I have to  say that in a not very documented way) the shutdown stops all Akka threads and the system appears to be released correctly (nevertheless in a single node configuration I don't see the typical shutdowing messages in the log).

Doing this the problem is solved. Thanks for your comments.

I still don't understand why the shutdown()/awaitTermination()  have no effect when those external threads are running. Probably when we migrate to 2.4 the problem will just vanish.

Thanks again!

Roland Kuhn

unread,
Mar 14, 2016, 3:12:54 AM3/14/16
to akka-user
Hi Eduardo,

threads created by other libraries are not managed by Akka, you will have to shut down that external DB interface yourself. The best place to do this would be in the actor’s postStop() hook (I mean that actor which also creates and uses that DB).

Regards,

Roland

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> 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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn


Eduardo Fernandes

unread,
Mar 14, 2016, 4:26:40 AM3/14/16
to akka...@googlegroups.com
Hi Roland.

Thanks for your answer.

Sure, the problem was that I was not aware about that threads. I'm afraid that I have to shutdown such threads at system shutdown because the library shares threads among several actor instances. Anyway, problem solved!

Thanks again for your time very helpful suggestions. 
Reply all
Reply to author
Forward
0 new messages