[Play 2.6.x Java] java.lang.OutOfMemoryError: Metaspace in dev mode

364 views
Skip to first unread message

Patrick Li

unread,
Oct 14, 2017, 1:07:57 AM10/14/17
to Play Framework
Hi all,

From time to time, I will get java.lang.OutOfMemoryError: Metaspace error from sbt. I looked around and found a few similar issues logged in Github project for Play, with some comments saying it could be the app not cleaning up its own resources such as DB connection. After looking through my code to make sure I am not leaving anything around, I tested things out with the play-java-starter project https://github.com/playframework/play-java-starter-example, and I can reproduce this error with it as well.

Steps to reproduce:
  1. Launch sbt and load the starter project in interactive mode
  2. Run the project with the run command in sbt
  3. Hit http://localhost:9000 in browser
  4. Hit enter or cmd D from sbt as soon as the page is loaded. This should keep you in the sbt interactive console
  5. Repeat step 2 - 4 a few times, and you will get the OOM error. For me, this usually happens after 5 or 6 runs
This will also happen with hot reloading, e.g. instead of hitting cmd D in step 4, make some changes in source code like an extra new line, and hit refresh in browser.

Does anyone run into this same issue?

Patrick

Patrick Li

unread,
Oct 14, 2017, 1:13:42 AM10/14/17
to Play Framework
Kind of like this issue https://github.com/lagom/lagom/issues/305, I know it is for Lagom, but steps to reproduce and symptom seem very similar.

alex s

unread,
Oct 14, 2017, 11:28:16 AM10/14/17
to Play Framework

суббота, 14 октября 2017 г., 8:07:57 UTC+3 пользователь Patrick Li написал:

Does anyone run into this same issue?

Everyone. This is a persistent issue with the technique sbt uses for nonforking run and test commands. It is not enough to make sure your own code doesn't prevent classloaders from being garbage collected, you must also make sure none of your dependencies does that.

Justin du coeur

unread,
Oct 16, 2017, 11:38:49 AM10/16/17
to play-fr...@googlegroups.com
I haven't tried it myself yet, but this library purports to help with this classloader leak...

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/90d1526d-e366-4b53-9601-f5c4a7e94d67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages