Skip to content

Commit 2a40bd7

Browse files
committed
Register shutdown hook so it can tidy up a partial refresh
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
1 parent f43970e commit 2a40bd7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ private void prepareContext(ConfigurableApplicationContext context, Configurable
394394
}
395395

396396
private void refreshContext(ConfigurableApplicationContext context) {
397-
refresh(context);
398397
if (this.registerShutdownHook) {
399398
try {
400399
context.registerShutdownHook();
@@ -403,6 +402,7 @@ private void refreshContext(ConfigurableApplicationContext context) {
403402
// Not allowed in some environments.
404403
}
405404
}
405+
refresh(context);
406406
}
407407

408408
private void configureHeadlessProperty() {

0 commit comments

Comments
 (0)