You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2023/05/11 21:01:28 UTC

[accumulo] branch 2.1 updated: halts when nested error seen in uncaught exception handler (#3396)

This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/2.1 by this push:
     new 6f7d3212d0 halts when nested error seen in uncaught exception handler (#3396)
6f7d3212d0 is described below

commit 6f7d3212d0909a62be113dd5252ac17f472090b2
Author: Keith Turner <kt...@apache.org>
AuthorDate: Thu May 11 17:01:22 2023 -0400

    halts when nested error seen in uncaught exception handler (#3396)
    
    Also changes code to assume a deeply nested exception that can not
    be fully inspected may contain an error.
---
 .../core/util/threads/AccumuloUncaughtExceptionHandler.java   | 11 ++++++-----
 .../util/threads/AccumuloUncaughtExceptionHandlerTest.java    |  6 +++---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/util/threads/AccumuloUncaughtExceptionHandler.java b/core/src/main/java/org/apache/accumulo/core/util/threads/AccumuloUncaughtExceptionHandler.java
index c5f413ce0c..1b01932721 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/threads/AccumuloUncaughtExceptionHandler.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/threads/AccumuloUncaughtExceptionHandler.java
@@ -36,8 +36,9 @@ class AccumuloUncaughtExceptionHandler implements UncaughtExceptionHandler {
 
     if (depth > 32) {
       // This is a peculiar exception. No error has been found, but recursing too deep may cause a
-      // stack overflow so going to stop.
-      return false;
+      // stack overflow so going to stop. Err on the side of caution and assume there could be an
+      // error since not everything was checked.
+      return true;
     }
 
     while (t != null) {
@@ -63,9 +64,7 @@ class AccumuloUncaughtExceptionHandler implements UncaughtExceptionHandler {
 
   @Override
   public void uncaughtException(Thread t, Throwable e) {
-    if (e instanceof Exception) {
-      LOG.error("Caught an Exception in {}. Thread is dead.", t, e);
-    } else if (isError(e)) {
+    if (isError(e)) {
       try {
         e.printStackTrace();
         System.err.println("Error thrown in thread: " + t + ", halting VM.");
@@ -75,6 +74,8 @@ class AccumuloUncaughtExceptionHandler implements UncaughtExceptionHandler {
       } finally {
         Runtime.getRuntime().halt(-1);
       }
+    } else {
+      LOG.error("Caught an Exception in {}. Thread is dead.", t, e);
     }
   }
 }
diff --git a/core/src/test/java/org/apache/accumulo/core/util/threads/AccumuloUncaughtExceptionHandlerTest.java b/core/src/test/java/org/apache/accumulo/core/util/threads/AccumuloUncaughtExceptionHandlerTest.java
index 23dfe6a0c2..f572fdf263 100644
--- a/core/src/test/java/org/apache/accumulo/core/util/threads/AccumuloUncaughtExceptionHandlerTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/util/threads/AccumuloUncaughtExceptionHandlerTest.java
@@ -92,12 +92,12 @@ public class AccumuloUncaughtExceptionHandlerTest {
     Exception e2 = new RuntimeException(new RuntimeException());
     Exception e3 = new IllegalStateException();
 
-    // create a chain of suppressed exceptions that forms a loop
+    // create an infinite loop of suppressed exceptions
     e1.addSuppressed(e2);
     e2.addSuppressed(e3);
     e3.addSuppressed(e1);
 
-    assertFalse(isError(e1));
-    assertFalse(isError(new RuntimeException(e1)));
+    assertTrue(isError(e1));
+    assertTrue(isError(new RuntimeException(e1)));
   }
 }