Skip to content
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

Application stuck on shutdown with custom scheduler #29301

Closed
alexey-anufriev opened this issue Jan 10, 2022 · 7 comments
Closed

Application stuck on shutdown with custom scheduler #29301

alexey-anufriev opened this issue Jan 10, 2022 · 7 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@alexey-anufriev
Copy link

Application stuck on shutdown if ConcurrentTaskScheduler is used and application has startup error.

Reproducer repository:
https://github.com/alexey-anufriev/spring-shutdown-stuck-with-custom-scheduler

Readme:
https://github.com/alexey-anufriev/spring-shutdown-stuck-with-custom-scheduler/blob/master/README.md

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 10, 2022
@snicoll
Copy link
Member

snicoll commented Jan 10, 2022

That sounds like the expected behavior to me. The non-working example is creating a task scheduler manually. You're then responsible to shut it down, which happens automatically when exposed as a @Bean.

@snicoll snicoll closed this as completed Jan 10, 2022
@snicoll snicoll added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 10, 2022
@alexey-anufriev
Copy link
Author

hi @snicoll,

here is attempt to fix it: alexey-anufriev/spring-shutdown-stuck-with-custom-scheduler@828bf9f

but the behavior is still the same

@philwebb
Copy link
Member

@alexey-anufriev I'm trying to reproduce the error, but I can't get it to fail in the IDE or by using java -jar. I do see things hang when using ./mvnw spring-boot:run. Are you seeing the problem in production, or is it only when using ./mvnw spring-boot:run?

@philwebb philwebb added status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged and removed status: invalid An issue that we don't feel is valid labels Jan 10, 2022
@philwebb philwebb reopened this Jan 10, 2022
@alexey-anufriev
Copy link
Author

@philwebb, you can check my README: https://github.com/alexey-anufriev/spring-shutdown-stuck-with-custom-scheduler/blob/master/README.md

or just run ./mvnw clean spring-boot:run -Dspring-boot.run.profiles=non-working

it is important to have a profile enabled.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 10, 2022
@philwebb
Copy link
Member

@alexey-anufriev I did that and replicated the problem when using ./mvnw spring-boot:run but I'm trying to find out if the problem happens outside of that. When I tried java -jar -Dspring-boot.run.profiles=non-working ./target/spring-shutdown-stuck-0.0.1-SNAPSHOT.jar the application didn't hang. Neither did it hang in the IDE with that profile active.

@philwebb philwebb added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jan 10, 2022
@snicoll
Copy link
Member

snicoll commented Jan 11, 2022

@philwebb that's because -Dspring-boot.run.profiles is specific to the Maven plugin. Setting that property in your IDE or when invoking a repackaged archive has no effect.

@alexey-anufriev my initial comment still stands. ConcurrentTaskScheduler is primarily meant for wrapping an existing ScheduledExecutorService. The default constructor though creates an internal default executor, with no way to shut it down. In your custom arrangement, we'd really recommend you to use ThreadPoolTaskScheduler. If you insist on using ConcurrentTaskScheduler then you should use the constructor that takes a ScheduledExecutorService and shut it down yourself.

I've created spring-projects/spring-framework#27914 to improve things in that area.

@snicoll snicoll closed this as completed Jan 11, 2022
@snicoll snicoll added status: invalid An issue that we don't feel is valid and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Jan 11, 2022
@alexey-anufriev
Copy link
Author

@snicoll, my initial thought was that spring boot just missed to close ConcurrentTaskScheduler but it turns out that this is rather a limitation of ConcurrentTaskScheduler. In any case, thank you for the issue you created and for the explanations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants