From 6c77c5a4ad82816b3e448364fc9168d9d4e1c44f Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 10 Nov 2022 13:49:33 -0800 Subject: [PATCH] When crashing, send a bug report last. 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 --- .../google/devtools/build/lib/bugreport/BugReport.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bugreport/BugReport.java b/src/main/java/com/google/devtools/build/lib/bugreport/BugReport.java index f4b4a81bcc8f06..87fba9f4f97f65 100644 --- a/src/main/java/com/google/devtools/build/lib/bugreport/BugReport.java +++ b/src/main/java/com/google/devtools/build/lib/bugreport/BugReport.java @@ -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; @@ -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