You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by br...@apache.org on 2021/01/13 16:32:00 UTC

[accumulo] branch 1.10 updated: Re-throw exception from LoggingRunnable (re #1808)

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

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


The following commit(s) were added to refs/heads/1.10 by this push:
     new 0187567  Re-throw exception from LoggingRunnable (re #1808)
0187567 is described below

commit 018756754ff0f289a8b30f846af8b7092270318d
Author: Brian Loss <br...@apache.org>
AuthorDate: Tue Jan 12 10:20:17 2021 -0500

    Re-throw exception from LoggingRunnable (re #1808)
    
    * Re-throw the caught Throwable unless we received a more serious
      Error when attempting to log the original Throwable. In that case
      propagate the more serious error instead.
---
 .../apache/accumulo/fate/util/LoggingRunnable.java | 36 ++++++++++++++++------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/fate/src/main/java/org/apache/accumulo/fate/util/LoggingRunnable.java b/fate/src/main/java/org/apache/accumulo/fate/util/LoggingRunnable.java
index d9a6f5e..bff18f3 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/util/LoggingRunnable.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/util/LoggingRunnable.java
@@ -34,20 +34,36 @@ public class LoggingRunnable implements Runnable {
     try {
       runnable.run();
     } catch (Throwable t) {
+      boolean errorOnRun = (t instanceof Error);
       try {
         log.error("Thread \"{}\" died {}", Thread.currentThread().getName(), t.getMessage(), t);
       } catch (Throwable t2) {
-        // maybe the logging system is screwed up OR there is a bug in the exception, like
-        // t.getMessage() throws a NPE
-        System.err.println(
-            "ERROR " + new Date() + " Failed to log message about thread death " + t2.getMessage());
-        t2.printStackTrace();
-
-        // try to print original exception
-        System.err
-            .println("ERROR " + new Date() + " Exception that failed to log : " + t.getMessage());
-        t.printStackTrace();
+        boolean errorOnLog = (t2 instanceof Error);
+        try {
+          // maybe the logging system is screwed up OR there is a bug in the exception, like
+          // t.getMessage() throws a NPE
+          System.err.println("ERROR " + new Date() + " Failed to log message about thread death "
+              + t2.getMessage());
+          t2.printStackTrace();
+
+          // try to print original exception
+          System.err
+              .println("ERROR " + new Date() + " Exception that failed to log : " + t.getMessage());
+          t.printStackTrace();
+        } catch (Throwable t3) {
+          // If printing to System.err didn't work then don't try to log that exception but do
+          // re-throw it if it's the most serious failure we've seen so far.
+          boolean errorOnPrint = (t3 instanceof Error);
+          if (errorOnPrint && !errorOnLog && !errorOnRun)
+            throw t3;
+        }
+
+        // If we got a more serious failure when attempting to log the message,
+        // then throw that instead of the original exception.
+        if (errorOnLog && !errorOnRun)
+          throw t2;
       }
+      throw t;
     }
   }