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
Avoid getting objects that have not completed initialization #26376
Conversation
@lijinxiong Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@lijinxiong Thank you for signing the Contributor License Agreement! |
Unit test is required. |
The code is in the comments above |
@quaff is correct: when providing a PR to address an issue, you need to introduce a JUnit Jupiter based unit test that fails before the fix and passes after the fix. A Java class with a |
@sbrannen Do I need to submit code for unit tests? |
Tests need to be submitted as part of the PR. You will find existing tests under For example, for the class you have modified, you will find Note, however, that a pure unit test does not always suffice. In other words, you may need to create a dedicated integration test. For examples, feel free to browse the existing test suite. It often helps to search in the same package for related test classes. |
Thank you very much |
Unit tests already in pr |
@lijinxiong I also found this problem recently, but from the previous issues #25667, It can be seen that Jhoeller is trying to solve #25667 thread deadlock, but the code in your PR will make Spring return to the thread deadlock problem again, Can you offer a better way to solve this problem? |
@lijinxiong You can try changing the top line of code to the third line of code. Will this problem still occur |
Completely removing the early singleton check like in this PR is not really a proper way out. If you'd like to avoid the circular reference problem completely, set your factory to Note that we are considering to disallow circular references by default in a future Spring Framework generation. However, as long as we need to be able to resolve circular references, the current code still seems to be the best we can do there. Also, please note that we generally recommend against concurrent bean initialization scenarios. In particular with respect to circular reference resolution, a single-threaded preInstantiateSingletons phase is the most reliable arrangement. If you need to initialize with multiple threads, at least apply |
in org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
Unit test
console log
The code after my changes