javaspringspring-bootmultithreadingstack-overflow

Intermittent stack overflow error in a spring boot application


We are in the middle of a testing. On one specific setup, we see the following error:

Servlet.service() for servlet [dispatcherServlet] in context with path [/] threw exception [Handler dispatch failed: java.lang.StackOverflowError] with root cause
 at java.base/java.lang.ThreadLocal$SuppliedThreadLocal.initialValue(ThreadLocal.java:305)
 at java.base/java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:195)
 at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:172)
 at java.base/java.lang.ThreadLocal$SuppliedThreadLocal.initialValue(ThreadLocal.java:305)
 at java.base/java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:195)
 at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:172)
 at java.base/java.lang.ThreadLocal$SuppliedThreadLocal.initialValue(ThreadLocal.java:305)
 at java.base/java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:195)
 at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:172)
 at java.base/java.lang.ThreadLocal$SuppliedThreadLocal.initialValue(ThreadLocal.java:305)
 at java.base/java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:195)
 at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:172)
 at java.base/java.lang.ThreadLocal$SuppliedThreadLocal.initialValue(ThreadLocal.java:305)
 at java.base/java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:195)
 at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:172)
...

 Error attributes: {timestamp=Wed Jan 22 15:50:3
1 UTC 2025, exception=java.lang.StackOverflowError, trace=java.lang.StackOverflowError

Environment: Spring Boot 3.3.2, Spring Framework 6.1.11, JDK 17

In the stack trace, there is no call from our code, only from java.base/java.lang

I looked between the last log from our code base to the next expected log message in our code base and there we are not starting a new thread and we are not reading/writing anything to a SQL DB.

After thoroughly researching, we haven't found any cases matching our specific problem.


Solution

  • Its a known bug to a range of jdk17 builts. Please update to a newer release of the jdk17 should help.

    https://bugs.java.com/bugdatabase/view_bug?bug_id=8319090