Skip to content

Commit

Permalink
When crashing, send a bug report last.
Browse files Browse the repository at this point in the history
It involves an RPC, which may not complete. Only attempt it after first emitting exit data, which ensures that the crash is handled correctly (e.g. that an OOM is treated as such, not an arbitrary crash).

PiperOrigin-RevId: 487630019
Change-Id: I8dcc330d20b49419288e9e73b89d39645d960f60
  • Loading branch information
justinhorvitz authored and copybara-github committed Nov 10, 2022
1 parent 455454a commit 6c77c5a
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,8 @@ public static void handleCrash(Crash crash, CrashContext ctx) {
synchronized (LOCK) {
logger.atSevere().withCause(throwable).log("Handling crash with %s", ctx);

// Don't try to send a bug report during a crash in a test, it will throw itself.
if (TestType.isInTest()) {
lastCrashingThrowable = throwable;
} else if (ctx.shouldSendBugReport()) {
sendBugReport(throwable, ctx.getArgs());
}

String crashMsg;
Expand All @@ -274,7 +271,14 @@ public static void handleCrash(Crash crash, CrashContext ctx) {
ctx.getEventHandler().handle(Event.fatal(crashMsg));

try {
// Emit exit data before sending a bug report. Bug reports involve an RPC, and given that
// we are crashing, who knows if it will complete. It's more important that we write
// exit code and failure detail information so that the crash can be handled correctly.
emitExitData(crash, ctx, numericExitCode, heapDumpPath);
// Don't try to send a bug report during a crash in a test, it will throw itself.
if (ctx.shouldSendBugReport() && !TestType.isInTest()) {
sendBugReport(throwable, ctx.getArgs());
}
} finally {
if (ctx.shouldHaltJvm()) {
// Avoid shutdown deadlock issues: If an application shutdown hook crashes, it will
Expand Down

0 comments on commit 6c77c5a

Please sign in to comment.