Why does my app throw a java.lang.StackOverflowError on a Free, Hobby, or Standard-1X dyno?


A Java application will throw a java.lang.StackOverflowError when a thread of execution consumes all of the memory available to that thread's stack. This usually results from a very deep method call stack.

In most cases, this error is caused by infinite recursion (a problem with your application code), but it is sometimes caused by a legitimately large use of a thread's stack. On Heroku's Free, Hobby, and Standard-1X dynos the default Java thread stack size is 512 KB (-Xss512k), which overrides the default JVM setting of 1 MB. This difference may cause an app to work locally, but throw a java.lang.StackOverflowError on the smaller Heroku dyno sizes.


You can increase the thread stack size on Heroku by adding the -Xss1m option to your Procfile. For example:

web: java -Xss1m -jar target/myapp.jar

Any JVM options in the Procfile will override the defaults set by Heroku.

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support