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

Continue with pre-instantiation when current bean is in creation already #34349

Closed
jhoeller opened this issue Jan 31, 2025 · 1 comment
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@jhoeller
Copy link
Contributor

As of 6.2, lenient locking may lead to BeanCurrentlyInCreationException on pre-instantiation if another thread has picked up this bean outside of a singleton lock already. While this should never happen in a well-designed bootstrap arrangement where common beans are supposed to come first (through depends-on declaration in dependent beans even for async initialization needs), we can safely ignore a top-level BeanCurrentlyInCreationException on mainline pre-instantiation (in the main bootstrap thread) and move on. Effectively, the skipped bean is expected to concurrently finish its initialization in its other thread while the main thread continues with initializing the rest of the non-lazy singleton beans.

@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Jan 31, 2025
@jhoeller jhoeller added this to the 6.2.3 milestone Jan 31, 2025
@jhoeller jhoeller self-assigned this Jan 31, 2025
@jhoeller jhoeller changed the title Continue with pre-instantiation phase when current bean is in creation already Continue with pre-instantiation when current bean is in creation already Jan 31, 2025
@jhoeller jhoeller reopened this Feb 12, 2025
@jhoeller
Copy link
Contributor Author

jhoeller commented Feb 12, 2025

This has been revised for an additional measure: Encountering a BeanCurrentlyInCreationException in the mainline bootstrap thread, we check whether the affected bean is currently in lenient creation and correspondingly wait for its creation finishing. This works for top-level beans as well as transitively referenced beans, largely restoring the behavior for unmanaged initialization as we had it in 6.1.x without fully enforcing the common singleton lock in all threads.

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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant