@@ -75,7 +75,7 @@ public static void uncaughtException(Thread thread, Throwable t)
7575            if  (t2  != t  && (t2  instanceof  FSError  || t2  instanceof  CorruptSSTableException ))
7676                logger .error ("Exception in thread {}" , thread , t2 );
7777        }
78-         JVMStabilityInspector . inspectThrowable (t );
78+         inspectThrowable (t ,  JVMStabilityInspector :: inspectDiskError ,  true );
7979    }
8080
8181    /** 
@@ -86,12 +86,12 @@ public static void uncaughtException(Thread thread, Throwable t)
8686     */ 
8787    public  static  void  inspectThrowable (Throwable  t ) throws  OutOfMemoryError 
8888    {
89-         inspectThrowable (t , JVMStabilityInspector ::inspectDiskError );
89+         inspectThrowable (t , JVMStabilityInspector ::inspectDiskError ,  false );
9090    }
9191
9292    public  static  void  inspectCommitLogThrowable (Throwable  t )
9393    {
94-         inspectThrowable (t , JVMStabilityInspector ::inspectCommitLogError );
94+         inspectThrowable (t , JVMStabilityInspector ::inspectCommitLogError ,  false );
9595    }
9696
9797    private  static  void  inspectDiskError (Throwable  t )
@@ -102,7 +102,7 @@ else if (t instanceof FSError)
102102            FileUtils .handleFSError ((FSError ) t );
103103    }
104104
105-     public  static  void  inspectThrowable (Throwable  t , Consumer <Throwable > fn ) throws  OutOfMemoryError 
105+     public  static  void  inspectThrowable (Throwable  t , Consumer <Throwable > fn ,  boolean   isUncaughtException ) throws  OutOfMemoryError 
106106    {
107107        boolean  isUnstable  = false ;
108108        if  (t  instanceof  OutOfMemoryError )
@@ -136,7 +136,20 @@ else if (t instanceof UnrecoverableIllegalStateException)
136136        }
137137
138138        // Anything other than an OOM, we should try and heap dump to capture what's going on if configured to do so 
139-         HeapUtils .maybeCreateHeapDump ();
139+         if  (isUncaughtException )
140+         {
141+             try 
142+             {
143+                 if  (DatabaseDescriptor .getDumpHeapOnUncaughtException ())
144+                 {
145+                     HeapUtils .maybeCreateHeapDump ();
146+                 }
147+             }
148+             catch  (Throwable  sub )
149+             {
150+                 t .addSuppressed (sub );
151+             }
152+         }
140153
141154        if  (t  instanceof  InterruptedException )
142155            throw  new  UncheckedInterruptedException ((InterruptedException ) t );
@@ -167,7 +180,7 @@ else if (t instanceof UnrecoverableIllegalStateException)
167180        }
168181
169182        if  (t .getCause () != null )
170-             inspectThrowable (t .getCause (), fn );
183+             inspectThrowable (t .getCause (), fn ,  isUncaughtException );
171184    }
172185
173186    private  static  final  Set <String > FORCE_HEAP_OOM_IGNORE_SET  = ImmutableSet .of ("Java heap space" , "GC Overhead limit exceeded" );
0 commit comments