New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deadlock when the application context is closed and System.exit(int) is then called during application context refresh #27049
Comments
As far as I can tell, this isn't a regression. Things behave the same in 2.3.x and 2.4.x. This is the same behaviour as was discussed in #23625 starting at this comment where we recommended disabling the shutdown hook and possibly using an exit code generator. I think the same advice may apply here but the OP on Stack Overflow said that things were working for them on 2.4.x so there may be something different going on here. I've asked them to provide a minimal sample so we can investigate further. |
The key thing that I'd missed in the question on Stack Overflow is that package com.example.demo;
import javax.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class So68099330Application {
private final ApplicationContext context;
public So68099330Application(ApplicationContext context) {
this.context = context;
}
@PostConstruct
void shutdown() {
System.exit(SpringApplication.exit(context, () -> 0));
}
public static void main(String[] args) {
SpringApplication.run(So68099330Application.class, args);
}
} The key difference is that the context has already been closed before calling |
@wilkinsona I think this is also related, because exact configuration worked before 2.4.5 -> spring-cloud/spring-cloud-task#835 (comment). It fits what is described here, but id does not fit that I had the problem on a 2.4.x version |
Via this question on Stack Overflow, a deadlock occurs if
System.exit(int)
is called during context refresh. This minimal app will reproduce the problem:A workaround is to set
spring.main.register-shutdown-hook
tofalse
.The deadlock looks like this:
It's
SpringApplicationShutdownHook
andmain
that are deadlocked.The text was updated successfully, but these errors were encountered: