Skip to content

Fixed a deadlock issue that prevented the process from exiting #29692

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

Closed
wants to merge 1 commit into from

Conversation

uyong
Copy link

@uyong uyong commented Dec 15, 2022

how deadlocks occur?

  1. when ApplicationContext call refresh() method, main thread will hold startupShutdownMonitor monitor;
  2. then call onRefresh() method, it will load the external WebServer and create it;
  3. Let's say I implemented this WebServer, i will check license before created it, when the certification fails, I call System.exit(1), want to exit the process;
  4. System.exit(1) will runHooks, ApplicationContext's shutdownHook will be call, It runs in another thread, name of 'SpringContextShutdownHook', it will wait the monitor startupShutdownMonitor, but the monitor still hold by main thread, to make matters worse, main thread blocking in onRefresh method, wait WebServer created.
  5. so, deadlock occur!!

Fix it:

shutdownHook does not need to acquire a monitor on startupShutdownMonitor , and doClose method is thread safe, it is enough to call it.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 15, 2022
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Jan 31, 2023
@snicoll
Copy link
Member

snicoll commented Aug 27, 2023

Thanks for the PR @uyong. Unfortunately, this is not easy to make up our mind based on a one liner change like this. Would you be able to provide a small app that reproduces the behavior you've described?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Aug 27, 2023
@snicoll
Copy link
Member

snicoll commented Oct 16, 2023

Closing due to lack of requested feedback. If the feedback is provided we can consider reopening.

@snicoll snicoll closed this Oct 16, 2023
@snicoll snicoll removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 16, 2023
@uyong
Copy link
Author

uyong commented Dec 7, 2023

@snicoll @sbrannen I'm sorry, but I'm just following this message now;
this is app spring-bug-verify

@snicoll
Copy link
Member

snicoll commented Dec 11, 2023

@uyong thanks for the sample. We don't think the proposed change is safe, I've created #31811 to revisit this part of the code. We'll make sure to test that against your sample.

@snicoll snicoll added the status: declined A suggestion or change that we don't feel we should currently apply label Dec 11, 2023
@snicoll
Copy link
Member

snicoll commented Dec 14, 2023

@uyong with the latest change in #31811, that sample exits as you expect.

@uyong
Copy link
Author

uyong commented Dec 19, 2023

@snicoll thank you

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: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants