In Spring Boot 2.3.0
we've introduced deferred JPA bootstrap by default. As a result we got a number of deadlock-related issues. Some relate to the way our own code was interacting with the EntityManagerFactory
or how the framework was applying locks and we fixed those. But others were report of user apps that look incidental, for instance using a repository in @PostConstruct
.
After considering the pros and cons of each approach, we've decided that asynchronous bootstrap mode should be opt-in and that we should clarify its behaviour and how users can easily opting-in to it, including if they have to manipulate the EMF on startup.
This issue is about flipping the default value. While it is late in the 2.3.x
cycle to do so, it is an optimisation and switching back to the previous behaviour should not have any user-facing consequence. The release notes for 2.3.x should also be updated.
Two companion issues are also available to generalize the spring.data.jpa.repositories.bootstrap-mode
property (#24248) and to provide a mechanism to know that the EMF lock has been lifted (see https://github.com/spring-projects/spring-framework/issues/26153).
Comment From: michaldo
@snicoll , as you wrote that internal Spring deadlock issues are fixed, I would like to report new one:
Since Spring Boot 2.3.5 I have deadlock on test. I have two tests. Each test has own Spring context. Individually each test pass, together there is a deadlock. I provide a gist with thread dump: https://gist.github.com/michaldo/19126c61c90297c0b593bbf8136fc4a7
I tried to investigate the case and It seems be related to: JpaRepositoriesAutoConfiguration#entityManagerFactoryBootstrapExecutorCustomizer
Deadlock happens only when the autoconfiguration is activated
Comment From: snicoll
Thanks for the report but please don't do that in a comment. A quick look at your stakctrace shows that OpenFeign is doing something on startup that triggers the deadlock. Please follow-up there. You'll also need to provide a small sample that showcases the problem.
Comment From: michaldo
Indeed, without OpenFeign the problem does not exists. Thanks