diff options
author | Janak Ramakrishnan <janakr@google.com> | 2016-03-14 16:19:40 +0000 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2016-03-15 11:59:30 +0000 |
commit | b6582fafb7f0d879a3a4ad667732900cadba3817 (patch) | |
tree | 2ab01b3ff8a6bdec20b1930357dfca6c080e5892 /src/main/java | |
parent | ce372c36a3c1c90197a69bb2f3870babfc1eef5e (diff) |
Description redacted.
--
MOS_MIGRATED_REVID=117139503
Diffstat (limited to 'src/main/java')
3 files changed, 45 insertions, 46 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java index 472a3e50d6..e47a81e5fb 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java @@ -32,7 +32,6 @@ import com.google.common.eventbus.SubscriberExceptionContext; import com.google.common.eventbus.SubscriberExceptionHandler; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Uninterruptibles; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.cache.ActionCache; import com.google.devtools.build.lib.actions.cache.CompactPersistentActionCache; import com.google.devtools.build.lib.actions.cache.NullActionCache; @@ -1268,25 +1267,13 @@ public final class BlazeRuntime { * telemetry and the proper exit code is reported. */ private static void setupUncaughtHandler(final String[] args) { - Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread thread, Throwable throwable) { - try { - BugReport.handleCrash(throwable, args); - } catch (Throwable t) { - System.err.println("An exception was caught in " + Constants.PRODUCT_NAME + "'s " - + "UncaughtExceptionHandler, a bug report may not have been filed."); - - System.err.println("Original uncaught exception:"); - throwable.printStackTrace(System.err); - - System.err.println("Exception encountered during UncaughtExceptionHandler:"); - t.printStackTrace(System.err); - - Runtime.getRuntime().halt(BugReport.getExitCodeForThrowable(throwable)); - } - } - }); + Thread.setDefaultUncaughtExceptionHandler( + new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread thread, Throwable throwable) { + BugReport.handleCrash(throwable, args); + } + }); } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java b/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java index 40e869d7ae..938ba057c7 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.runtime; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BlazeVersionInfo; import com.google.devtools.build.lib.util.ExitCode; import com.google.devtools.build.lib.util.LoggingUtil; @@ -77,28 +78,46 @@ public abstract class BugReport { /** * Print and send a bug report, and exit with the proper Blaze code. Does not exit if called a - * second time. + * second time. This method tries hard to catch any throwables thrown during its execution and + * halts the runtime in that case. */ public static void handleCrash(Throwable throwable, String... args) { - if (alreadyHandlingCrash.compareAndSet(false, true)) { - int exitCode = getExitCodeForThrowable(throwable); - try { - logCrash(throwable, args); - if (runtime != null) { - runtime.notifyCommandComplete(exitCode); - // We don't call runtime#shutDown() here because all it does is shut down the modules, and - // who knows if they can be trusted. + int exitCode = getExitCodeForThrowable(throwable); + try { + if (alreadyHandlingCrash.compareAndSet(false, true)) { + try { + logCrash(throwable, args); + if (runtime != null) { + runtime.notifyCommandComplete(exitCode); + // We don't call runtime#shutDown() here because all it does is shut down the modules, + // and who knows if they can be trusted. + } + } finally { + // Avoid shutdown deadlock issues: If an application shutdown hook crashes, it will + // trigger our Blaze crash handler (this method). Calling System#exit() here, would + // therefore induce a deadlock. This call would block on the shutdown sequence completing, + // but the shutdown sequence would in turn be blocked on this thread finishing. Instead, + // exit fast via halt(). + Runtime.getRuntime().halt(exitCode); } - } finally { - // Avoid shutdown deadlock issues: If an application shutdown hook crashes, it will trigger - // our Blaze crash handler (this method). Calling System#exit() here, would therefore induce - // a deadlock. This call would block on the shutdown sequence completing, but the shutdown - // sequence would in turn be blocked on this thread finishing. Instead, exit fast via - // halt(). - Runtime.getRuntime().halt(exitCode); + } else { + logCrash(throwable, args); } - } else { - logCrash(throwable, args); + } catch (Throwable t) { + System.err.println( + "An crash occurred while " + + Constants.PRODUCT_NAME + + " was trying to handle a crash! Please file a bug against " + + Constants.PRODUCT_NAME + + " and include the information below."); + + System.err.println("Original uncaught exception:"); + throwable.printStackTrace(System.err); + + System.err.println("Exception encountered during BugReport#handleCrash:"); + t.printStackTrace(System.err); + + Runtime.getRuntime().halt(exitCode); } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/OomSignalHandler.java b/src/main/java/com/google/devtools/build/lib/runtime/OomSignalHandler.java index 8338c2398e..39c2c8902c 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/OomSignalHandler.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/OomSignalHandler.java @@ -41,13 +41,6 @@ class OomSignalHandler extends AbstractSignalHandler { LOG.info(message); OutErr.SYSTEM_OUT_ERR.printErrLn( "Exiting as if we OOM'd because SIGUSR2 received, presumably from JVM"); - try { - BugReport.handleCrash(new OutOfMemoryError(message)); - } finally { - // This block should never be reached because BugReport.handleCrash halts the JVM, but just in - // case. - System.err.println("Failed to exit with OOM error code"); - Runtime.getRuntime().halt(ExitCode.OOM_ERROR.getNumericExitCode()); - } + BugReport.handleCrash(new OutOfMemoryError(message)); } } |