Hi.

We hit serious PermGen leak when used akka in war/ear application. We used 
this pattern for shutting down ActorSystem while destroying application:

actorSystem.shutdown();
actorSystem.awaitTermination();


Redeploying application then caused java.lang.OutOfMemoryError: PermGen 
space. Root cause was leaked thread ForkJoinPool-3-worker-3, which 
prevented WebappClassLoader from being garbage collected. All dispatcher 
threads have been destroyed. After hours of debugging and by elemination we 
identified source of this leaked thread. Leak is caused by Remoting#shutdown 
method which imports scala.concurrent.ExecutionContext.Implicits.global. 
When shutting down remoting, new ForkJoinPool (ForkJoinPool-3) is created 
and one thread remains, which holds ClassLoader in field contextClassLoader. 
ForkJoinPool-1 and ForkJoinPool-2 were created by default-dispatcher and 
default-remote-dispatcher.

Our current workaround is termination callback which is responsible for 
shutting down global ExecutionContext. I'm not sure, if this is 100% 
working solution (or rather call executorService.shutdown() after 
actorSystem.awaitTermination()), but at least leaking thread is no longer 
present after shutting down application.

actorSystem.registerOnTermination(new Runnable() {
   @Override
   public void run() {
      ExecutionContextImpl executorImpl = (ExecutionContextImpl) 
ExecutionContext.Implicits$.MODULE$.global();
      AbstractExecutorService executorService = (AbstractExecutorService) 
executorImpl.executor();

      executorService.shutdown();
      try {
         executorService.awaitTermination(10, TimeUnit.SECONDS);
         LOGGER.info("Shutting down ExecutionContext.Implicits.global 
completed.");
      } catch (InterruptedException e) {
         LOGGER.error("Shutting down ExecutionContext.Implicits.global 
failed.", e);
      }
   }
});


Is there some reason why is Remoting#shutdown using 
scala.concurrent.ExecutionContext.Implicits.global instead of some thread 
created by akka (e.g. dispatcher thread)? Who is then responsible for 
shutting down global ExecutionContext thread pool?

Thanks

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to