Avoid calling full shutdown sequence in MemoizingEvaluator when crashing. Just do basic stats logging.

PiperOrigin-RevId: 248346964
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 a08a4ff..7e57e8b 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
@@ -528,25 +528,18 @@
       // exiting for us.
       EventBus eventBus = workspace.getSkyframeExecutor().getEventBus();
       if (eventBus != null) {
-        try {
-          workspace
-              .getSkyframeExecutor()
-              .notifyCommandComplete(
-                  new ExtendedEventHandler() {
-                    @Override
-                    public void post(Postable obj) {
-                      eventBus.post(obj);
-                    }
+        workspace
+            .getSkyframeExecutor()
+            .postLoggingStatsWhenCrashing(
+                new ExtendedEventHandler() {
+                  @Override
+                  public void post(Postable obj) {
+                    eventBus.post(obj);
+                  }
 
-                    @Override
-                    public void handle(Event event) {}
-                  });
-        } catch (InterruptedException e) {
-          logger.severe("InterruptedException when crashing: " + e);
-          // Follow the convention of interrupting the current thread, even though nothing can throw
-          // an interrupt after this.
-          Thread.currentThread().interrupt();
-        }
+                  @Override
+                  public void handle(Event event) {}
+                });
         eventBus.post(new CommandCompleteEvent(exitCode.getNumericExitCode()));
       }
     }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index 5865ca1..501f129 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -825,6 +825,14 @@
     memoizingEvaluator.noteEvaluationsAtSameVersionMayBeFinished(eventHandler);
   }
 
+  /**
+   * Notifies the executor to post logging stats when the server is crashing, so that logging is
+   * still available even when the server crashes.
+   */
+  public void postLoggingStatsWhenCrashing(ExtendedEventHandler eventHandler) {
+    memoizingEvaluator.postLoggingStats(eventHandler);
+  }
+
   protected abstract Differencer evaluatorDiffer();
 
   protected abstract T getBuildDriver();
diff --git a/src/main/java/com/google/devtools/build/skyframe/MemoizingEvaluator.java b/src/main/java/com/google/devtools/build/skyframe/MemoizingEvaluator.java
index 1fc8fdb..34d57aa 100644
--- a/src/main/java/com/google/devtools/build/skyframe/MemoizingEvaluator.java
+++ b/src/main/java/com/google/devtools/build/skyframe/MemoizingEvaluator.java
@@ -101,7 +101,16 @@
    * guaranteed to be at the same version.
    */
   default void noteEvaluationsAtSameVersionMayBeFinished(ExtendedEventHandler eventHandler)
-      throws InterruptedException {}
+      throws InterruptedException {
+    postLoggingStats(eventHandler);
+  }
+
+  /**
+   * Tells the evaluator to post any logging statistics that it may have accumulated over the last
+   * sequence of evaluations. Normally called internally by {@link
+   * #noteEvaluationsAtSameVersionMayBeFinished}.
+   */
+  default void postLoggingStats(ExtendedEventHandler eventHandler) {}
 
   /**
    * Returns the done (without error) values in the graph.