-
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
Async advisor retrieval blocks when triggered by singleton init method [SPR-14324] #18896
Comments
Juergen Hoeller commented Could you elaborate a bit? What behavior are you seeing? That synchronization change in 4.2.6, driven by #18814, was meant to avoid a deadlock between the local lock here and the context-wide singleton lock. This may lead to longer lock times for some calls which should be acceptable given that it avoids deadlocks. Or are you saying that you're seeing a deadlock now against 4.2.6 which you haven't had against 4.2.5? |
Chris Klinger commented It seems that we have a similar issue with our application here, but i wasn't able to reproduce it in a "simple" test case yet. The scenario is: The application context is populated over several configurations, one of them is responsible for building up a elastic search index if not existing in My analysis shows: The Main thread starting up the application context owns the The application is starting with 4.2.5 but not with 4.2.6. Additional observation we can't explain yet is that the application is starting up in 4.2.5 with single core configuration (that uses context scan to find additional ones) but not in an integration test using Spring JUnit Runner. In this case i additionally have to pass the Configuration class with the |
Efi Cohen commented We are seeing a very similar problem after upgrading from 4.2.4 Application threads are stuck in BLOCKED state and the application won't start (seems like a deadlock as it never gets out from the blocked state) java.lang.Thread.State: BLOCKED
It's happening every time we try and start the app with the new spring version |
Juergen Hoeller commented Efi Cohen, do you have a thread dump for the thread that's holding the lock ("main") as well? Which thread is triggering that advisor resolution step here, and which code initiated that thread to begin with? Is that code waiting for the other thread to finish, causing the deadlock that way? In other words, do you happen to have any singleton initialization code that delegates out to an asynchronous task, waiting for it to return before completing the singleton's own initialization... and therefore not releasing the singleton lock before the other thread finishes? |
Juergen Hoeller commented Generally speaking, it's a highly fragile arrangement to wait for an asynchronous task from an init method ( For a possible refinement, we could leniently retrieve existing singleton instances like we did before, only running into the actual singleton lock for a newly created bean. I'm giving this a try for 4.3.4, to be backported to 4.2.9. |
Efi Cohen commented
The main is executing a synchronous code in a bean's post construct |
Juergen Hoeller commented Alright, that's analogous to the scenario outlined by Chris Klinger above then: an init method waiting for an async task to complete, with that async task having an aspect/advisor that refers back to a singleton bean in the factory. Just to be clear, this would not have worked before either if that singleton bean didn't exist yet... but point taken, the changes behind #18961 (your particular case) or #18814 (Chris Klinger's case) make it block for existing singleton beans as well now. I'll revise this for 4.3.4 and 4.2.9, avoiding an explicit lock for existing instances... but I highly recommend a revision on your side where your |
Efi Cohen commented Thanks, much appreciated |
terry.zhu opened SPR-14324 and commented
in spring 4.2.6
class: LazySingletonAspectInstanceFactoryDecorator
method:getAspectInstance
thread is blocked.
please see:https://github.com/zhuyijian135757/http-server.git
run: class Booter
run test: class HttpClientCase
Affects: 3.2.17, 4.2.6, 4.3 GA
Reference URL: https://github.com/zhuyijian135757/http-server.git
Attachments:
Issue Links:
Backported to: 4.2.9, 3.2.18
1 votes, 4 watchers
The text was updated successfully, but these errors were encountered: