title: Spring boot requests hang when getting OutOfMemoryError in web server threads
body: <p>Due to some bug, my app is consuming too much memory and heap space is running out.</p>
  
  <p>However, instead of requests failing, I'm getting an infinite hang and only following error in console:</p>
  
  <pre><code>*** 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"
  </code></pre>
  
  <p>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)</p>
  
  <p>My code to kill the service:</p>
  
  <pre><code>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());
    ...
  }
  </code></pre>
  
  <p>(<code>System.exit()</code> was hanging as well)</p>
  
  <p>I'm using Java 11 with Spring Boot version 2.1.6</p>