Due to some bug, my app is consuming too much memory and heap space is running out.
However, instead of requests failing, I'm getting an infinite hang and only following error in console:
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message can't create name string at JPLISAgent.c line: 826
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "http-nio-8090-ClientPoller"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Catalina-utility-2"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Catalina-utility-1"
Why are requests hanging and not failing? Is the only solution (besides not reaching out of memory to begin with) is to kill the service? (Its running in a container so it will get restarted)
My code to kill the service:
static class GlobalThreadExceptionHandler implements UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
logger.error(String.format("Caught unhandled exception in thread %s", thread), throwable);
Runtime.getRuntime().halt(137);
}
}
public static void main(String[] args) {
Thread.setDefaultUncaughtExceptionHandler(new GlobalThreadExceptionHandler());
...
}
(System.exit()
was hanging as well)
I'm using Java 11 with Spring Boot version 2.1.6