Skip to content

Wait for dependent lifecycle shutdown callbacks - #37340

Open
kimsanhaa wants to merge 1 commit into
spring-projects:mainfrom
kimsanhaa:fix/lifecycle-shutdown-dependencies
Open

kimsanhaa wants to merge 1 commit into
spring-projects:mainfrom
kimsanhaa:fix/lifecycle-shutdown-dependencies

Conversation

@kimsanhaa

@kimsanhaa kimsanhaa commented Sep 28, 2026 •

Copy link
Copy Markdown

Closes gh-28277.

DefaultLifecycleProcessor sizes each shutdown latch from the beans in one phase, but dependent beans in other phases decrement the same latch. A fast dependent can therefore let close() return while another shutdown callback is still pending.

Register shutdown participants with a Phaser as beans are stopped, including their dependents. Keep one coordinator registered until all stop calls have been issued so synchronous callbacks cannot end the wait early. Phase timeouts and interruption handling are preserved.

Regression tests defer either the higher-phase or the dependent bean's callback and verify that shutdown waits. Another test verifies that a dependent bean cannot prevent shutdown after the configured timeout.

Validation: :spring-context:check passes. All 27 DefaultLifecycleProcessorTests pass with -PtestGroups=LONG_RUNNING. Enabling that group for the whole module exposes two failures in BackgroundBootstrapTests.bootstrapWithCustomExecutorAndLazyConfig and EnableSchedulingTests.withExplicitScheduler; both reproduce on unmodified main at 93ff61fb1f.

Register shutdown participants as beans are stopped so callbacks from
dependent beans in another phase cannot end the wait prematurely.
Preserve phase timeouts and cover both callback completion orders.

Closes spring-projectsgh-28277

Signed-off-by: kimsanha <[email protected]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 28, 2026
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Sep 28, 2026

This branch has not been deployed

No deployments
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) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DefaultLifecycleProcessor doesn't wait for a Phase to stop completely if its bean is dependent on other SmartLifeCycle bean

3 participants