Issue
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 Eco, Basic, (formerly 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.
Resolution
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.
WARNING: Starting November 28, 2022, free Heroku Dynos, free Heroku Postgres, and free Heroku Data for Redis plans will no longer be available. If you have apps using any of these resources, you must upgrade to paid plans by this date to ensure your apps continue to run and retain your data. Eligible students can apply for platform credits through our new Heroku for GitHub Students program. See our blog and FAQ for more info.