Skip to content

Commit a2ba01b

Browse files
pauloricardomgPaulo Motta
authored andcommitted
Heap dump should not be generated on handled exceptions
1 parent ed04f46 commit a2ba01b

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/java/org/apache/cassandra/utils/HeapUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public static String maybeCreateHeapDump()
130130
}
131131
else
132132
{
133-
logger.debug("Heap dump creation on uncaught exceptions is disabled.");
133+
logger.trace("Heap dump creation on uncaught exceptions is disabled.");
134134
}
135135
}
136136
catch (Throwable e)

src/java/org/apache/cassandra/utils/JVMStabilityInspector.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)