Skip to content

Commit

Permalink
Register shutdown hook so it can tidy up a partial refresh
Browse files Browse the repository at this point in the history
Previously, the shutdown hook was only registered once refresh has
completed. If the JVM was shut down during refresh (or after refresh
and before the hook was registered) the hook wouldn't run and the
partially refreshed context would not be cleaned up.

This commit moves the registration of the shutdown hook to before
refresh processing begins. This ensures that the hook is available
to clean up the context if the JVM is shutdown while refresh is in
progress.

Fixes gh-23625
  • Loading branch information
wilkinsona committed Oct 19, 2020
1 parent f43970e commit 2a40bd7
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ private void prepareContext(ConfigurableApplicationContext context, Configurable
}

private void refreshContext(ConfigurableApplicationContext context) {
refresh(context);
if (this.registerShutdownHook) {
try {
context.registerShutdownHook();
Expand All @@ -403,6 +402,7 @@ private void refreshContext(ConfigurableApplicationContext context) {
// Not allowed in some environments.
}
}
refresh(context);
}

private void configureHeadlessProperty() {
Expand Down

0 comments on commit 2a40bd7

Please sign in to comment.