-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Initialization blocked by multi-threaded event publishing [SPR-16357] #20904
Comments
Juergen Hoeller commented This is a tough one since it relates to the general challenges of parallel bean initialization. At this point, we generally don't support custom threads triggering (singleton) bean initialization while the main thread is waiting on them. |
Brian Clozel commented Apart from the general challenge, I wanted to point out that the driver for this issue is the following: being able to call initialization code during application startup using |
Sébastien Deleuze commented I faced the issue described by Brian Clozel in my reference Kotlin + Spring Reactive application https://github.com/mixitconf/mixit, and I could not find a satisfying solution, so I would like to know if we could improve that. I need to initialize data in my MongoDB instance with
With Boot 2.0.2 it was working (by luck I think), but if I upgrade to Boot 2.0.6 or 2.1.1, it is blocking indefinitely at I quote mp911de explanation:
The only solution we have here is to use a blocking I don't know if we could find a way to avoid this deadlock or support |
Dave Syer commented I think |
Brian Clozel commented Looking at Juergen Hoeller's comments in #21025, I don't think we'll have a reactive way of publishing/processing events - for the same reason, supporting |
Sébastien Deleuze commented Dave Syer I was mistaken by spring-projects/spring-boot#7656 where application and command line runners were initially moved after ready event, then it was rollbacked. I did some test with my MiXiT application, and I can confirm the data are created before my integration tests. That said using Also I still think that a lot of users will be spend lot of time stuck on the |
Sébastien Deleuze commented I confirm |
@jhoeller - I am using spring 5.2.8 and still seeing this issue. Any updates on the fix? Our project is trying to load the application cache using multiple parallel threads during @PostConstruct of the Cacheloader bean. If any of the threads has some issue while loading the cache we publish the issue as an events . A listener listens to those events and log the issue to the external system. I am seeing deadlock while cache loader threads trying to publish the events using spring ApplicationEventpublisher. |
With #25799 having been addressed years ago and #23501 revised for 6.2 now, there should not be any blocking for asynchronous event publication anymore. #25799 made it work fine for existing listeners, #23501 makes it work for listener beans that need to be initialized yet as well (unless there is a conflict among the dependencies created for that listener). |
Mark Paluch opened SPR-16357 and commented
Publishing events can block the container initialization in conjunction with event publishing from a different thread.
This can happen if events are published from a bean constructor while its bean is instantiated and events get published in a different thread while the constructed bean awaits completion of event publishing.
Consider following code:
The code above publishes an event in an other thread than the constructing thread while awaiting completion before the constructor progresses.
It leads to a thread state like:
The example originates from reactive code in which a constructor is used to call initialization code using
.block()
for synchronization, see DATAMONGO-1841.Affects: 5.0 GA
Issue Links:
0 votes, 8 watchers
The text was updated successfully, but these errors were encountered: