Move outer Runtime#halt in BugReport#handleCrash into finally block, just for some belt-and-suspenders security.
Add verbose logging for impossible situation of continuing after a crash, and add some logging that can stick around even when we resolve the bug, since it should never be hit.
@@ -209,19 +209,26 @@ public abstract class BugReport {
if (runtime != null) {
runtime.cleanUpForCrash(detailedExitCode);
}
+ // TODO(b/167592709): remove verbose logging when bug resolved.
+ logger.atInfo().log("Finished runtime cleanup");
CustomExitCodePublisher.maybeWriteExitStatusFile(numericExitCode);
+ logger.atInfo().log("Wrote exit status file");
CustomFailureDetailPublisher.maybeWriteFailureDetailFile(
detailedExitCode.getFailureDetail());
+ logger.atInfo().log("Wrote failure detail file");
} finally {
+ logger.atInfo().log("Entered inner finally block");
// 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(numericExitCode);
+ logger.atSevere().log("Failed to halt (inner block)!");
}
}
} catch (Throwable t) {
+ logger.atSevere().withCause(t).log("Threw while crashing");
System.err.println(
"ERROR: A crash occurred while "
+ getProductName()
@@ -234,9 +241,12 @@ public abstract class BugReport {
System.err.println("Exception encountered during BugReport#handleCrash:");
t.printStackTrace(System.err);
-
+ } finally {
+ logger.atInfo().log("Entered outer finally block");
Runtime.getRuntime().halt(numericExitCode);
+ logger.atSevere().log("Failed to halt (outer block)!");
}
+ logger.atSevere().log("Failed to crash in handleCrash");
throw new IllegalStateException("never get here", throwable);
}
