@@ -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,18 @@ 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 && DatabaseDescriptor .getDumpHeapOnUncaughtException ())
140+ {
141+ try
142+ {
143+ // Avoid entering maybeCreateHeapDump unless the setting is enabled to avoid expensive lock
144+ HeapUtils .maybeCreateHeapDump ();
145+ }
146+ catch (Throwable sub )
147+ {
148+ t .addSuppressed (sub );
149+ }
150+ }
140151
141152 if (t instanceof InterruptedException )
142153 throw new UncheckedInterruptedException ((InterruptedException ) t );
@@ -167,7 +178,7 @@ else if (t instanceof UnrecoverableIllegalStateException)
167178 }
168179
169180 if (t .getCause () != null )
170- inspectThrowable (t .getCause (), fn );
181+ inspectThrowable (t .getCause (), fn , isUncaughtException );
171182 }
172183
173184 private static final Set <String > FORCE_HEAP_OOM_IGNORE_SET = ImmutableSet .of ("Java heap space" , "GC Overhead limit exceeded" );
0 commit comments