Skip to content

Commit 8c5765d

Browse files
pauloricardomgPaulo Motta
authored andcommitted
Heap dump should not be generated on handled exceptions
Patch by Paulo Motta; Reviewed by Isaac Reath, Stefan Miklosovic for CASSANDRA-20974
1 parent ed04f46 commit 8c5765d

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
5.0.6
2+
* Heap dump should not be generated on handled exceptions (CASSANDRA-20974)
23
* Throw RTE instead of FSError when RTE is thrown from FileUtis.write in TOCComponent (CASSANDRA-20917)
34
* Upgrade jackson-dataformat-yaml to 2.19.2 and snakeyaml to 2.1 (CASSANDRA-18875)
45
* Represent complex settings as JSON on system_views.settings table (CASSANDRA-20827)

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ public static String maybeCreateHeapDump()
128128

129129
return fullPath;
130130
}
131-
else
132-
{
133-
logger.debug("Heap dump creation on uncaught exceptions is disabled.");
134-
}
135131
}
136132
catch (Throwable e)
137133
{

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

Lines changed: 21 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,22 @@ 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+
// Avoid entering maybeCreateHeapDump unless the setting is enabled
144+
// since that will attempt to grab an expensive lock
145+
if (DatabaseDescriptor.getDumpHeapOnUncaughtException())
146+
{
147+
HeapUtils.maybeCreateHeapDump();
148+
}
149+
}
150+
catch (Throwable sub)
151+
{
152+
t.addSuppressed(sub);
153+
}
154+
}
140155

141156
if (t instanceof InterruptedException)
142157
throw new UncheckedInterruptedException((InterruptedException) t);
@@ -167,7 +182,7 @@ else if (t instanceof UnrecoverableIllegalStateException)
167182
}
168183

169184
if (t.getCause() != null)
170-
inspectThrowable(t.getCause(), fn);
185+
inspectThrowable(t.getCause(), fn, isUncaughtException);
171186
}
172187

173188
private static final Set<String> FORCE_HEAP_OOM_IGNORE_SET = ImmutableSet.of("Java heap space", "GC Overhead limit exceeded");

0 commit comments

Comments
 (0)