Prevent new commands from starting if Bazel is in the middle of crashing: crashing can take quite a long time during clean-up, and it's confusing if another command runs in the middle of it. This became much more likely after https://github.com/bazelbuild/bazel/commit/5ebcf97e655797cf3715806fff55e7fa3c5a61b9, since the command thread is interrupted in a crash now, so control is returned to the caller.

PiperOrigin-RevId: 383564388
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BlazeRuntimeTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BlazeRuntimeTest.java
index a80e7b0..3639fe9 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/BlazeRuntimeTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/BlazeRuntimeTest.java
@@ -37,6 +37,7 @@
 import com.google.protobuf.BytesValue;
 import com.google.protobuf.StringValue;
 import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicReference;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -81,10 +82,11 @@
     BlazeRuntime runtime =
         new BlazeRuntime.Builder()
             .setFileSystem(fs)
-            .setProductName("bazel")
+            .setProductName("foo product")
             .setServerDirectories(serverDirectories)
             .setStartupOptionsProvider(Mockito.mock(OptionsParsingResult.class))
             .build();
+    AtomicReference<String> shutdownMessage = new AtomicReference<>();
     BlazeDirectories directories =
         new BlazeDirectories(
             serverDirectories, fs.getPath("/workspace"), fs.getPath("/system_javabase"), "blaze");
@@ -104,7 +106,8 @@
             ImmutableList.of(),
             0L,
             0L,
-            ImmutableList.of());
+            ImmutableList.of(),
+            shutdownMessage::set);
     runtime.beforeCommand(env, options.getOptions(CommonCommandOptions.class));
     DetailedExitCode oom =
         DetailedExitCode.of(
@@ -120,6 +123,7 @@
     assertThat(runtime.afterCommand(env, mainThreadCrash).getDetailedExitCode()).isEqualTo(oom);
     // Confirm that runtime interrupted the command thread.
     verify(commandThread).interrupt();
+    assertThat(shutdownMessage.get()).isEqualTo("foo product is crashing: ");
   }
 
   @Test
@@ -150,7 +154,8 @@
             ImmutableList.of(),
             0L,
             0L,
-            ImmutableList.of());
+            ImmutableList.of(),
+            s -> {});
     Any anyFoo = Any.pack(StringValue.of("foo"));
     Any anyBar = Any.pack(BytesValue.of(ByteString.copyFromUtf8("bar")));
     env.addResponseExtensions(ImmutableList.of(anyFoo, anyBar));