diff options
Diffstat (limited to 'src')
3 files changed, 24 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java index a2e71cc9a4..e6cce932fb 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java @@ -241,11 +241,23 @@ public abstract class BlazeModule { /** * Called when Blaze shuts down. + * + * <p>If you are also implementing {@link #shutdownOnCrash()}, consider putting the common + * shutdown code in the latter and calling that other hook from here. */ public void blazeShutdown() { } /** + * Called when Blaze shuts down due to a crash. + * + * <p>Modules may use this to flush pending state, but they must be careful to only do a minimal + * number of things. Keep in mind that we are crashing so who knows what state we are in. Modules + * rarely need to implement this. + */ + public void blazeShutdownOnCrash() {} + + /** * Perform module specific check of current command environment. */ public void checkEnvironment(CommandEnvironment env) { 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 dc67a17f9d..9d040bd31d 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 @@ -473,12 +473,20 @@ public final class BlazeRuntime { return commandMap; } + /** Invokes {@link BlazeModule#blazeShutdown()} on all registered modules. */ public void shutdown() { for (BlazeModule module : blazeModules) { module.blazeShutdown(); } } + /** Invokes {@link BlazeModule#blazeShutdownOnCrash()} on all registered modules. */ + public void shutdownOnCrash() { + for (BlazeModule module : blazeModules) { + module.blazeShutdownOnCrash(); + } + } + /** * Returns the defaults package for the default settings. Should only be called by commands that * do <i>not</i> process {@link BuildOptions}, since build options can alter the contents of the diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java b/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java index aadaf10c51..9a6e978878 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java @@ -89,7 +89,10 @@ public abstract class BugReport { if (runtime != null) { runtime.notifyCommandComplete(exitCode); // We don't call runtime#shutDown() here because all it does is shut down the modules, - // and who knows if they can be trusted. + // and who knows if they can be trusted. Instead, we call runtime#shutdownOnCrash() + // which attempts to cleanly shutdown those modules that might have something pending + // to do as a best-effort operation. + runtime.shutdownOnCrash(); } } finally { // Avoid shutdown deadlock issues: If an application shutdown hook crashes, it will |