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

ThreadPoolTaskExecutor rejecting tasks as soon as the context has been closed can lead to exceptions during web app shutdown #32226

Closed
wilkinsona opened this issue Feb 8, 2024 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@wilkinsona
Copy link
Member

Affects: 6.1.3

As discussed with @jhoeller, spring-projects/spring-boot#39469 has highlighted a problem with ThreadPoolTaskExecutor rejecting tasks once it has received a ContextClosedEvent. In a Spring Boot web application this creates a window where the task executor cannot be used but the web server is still accepting requests. Those requests will fail if they try to use the executor.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 8, 2024
@jhoeller jhoeller added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 8, 2024
@jhoeller jhoeller self-assigned this Feb 8, 2024
@jhoeller jhoeller added this to the 6.1.4 milestone Feb 8, 2024
@jhoeller
Copy link
Contributor

jhoeller commented Feb 11, 2024

ThreadPoolTaskExecutor (and also ThreadPoolExecutorFactoryBean) leniently accepts tasks after context close in combination with the coordinated lifecycle stop phase now. So this is not setAcceptTasksAfterContextClose(true) by default (which would bypass the lifecycle stop phase altogether) but rather lenient acceptance of further tasks which will nevertheless be rolled into the lifecycle stop phase, waiting for all such late submissions to complete still, resulting in a lenient variant of a graceful shutdown.

Schedulers remain strict on shutdown (otherwise the triggers would keep firing while we wait for all tasks to complete), just plain executors are lenient on shutdown now. An early shutdown for executors with strict rejecting of further task submissions can be enforced via setStrictEarlyShutdown(true).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants