-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Improve annotation processing thread-safety #2
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Commit http://bit.ly/nXumTs ensured that component methods and fields marked with 'common annotations' such as @resource, @PostConstruct and @PreDestroy are invoked/assigned once and only once, even if multiple instances of the CommonAnnotationBeanPostProcessor are processing the same bean factory. The implementation works against the InjectionMetadata API, adding and removing these members from sets that track whether they are already 'externally managed', i.e. that another CABPP has already handled them, thus avoiding redundant processing. Prior to this change, the #remove operations against these sets were not synchronized. In a single-threaded context this is fine thanks to logic in AbstractAutowireCapableBeanFactory#doCreateBean that checks to see whether a given bean definition has already been post processed. However, as reported by SPR-8598, certain cases involving multiple threads and annotated prototype-scoped beans can cause concurrent modification exceptions during the #remove operation (ostensibly because another thread is attempting to do the same removal at the same time, though this has yet to be reproduced in isolation). Now the sets originally introduced by the commit above are decorated with Collections#synchronizedSet and any iterations over those sets are synchronized properly. This change should have low performance impact as such processing happens at container startup time (save for non-singleton lookups at runtime), and there should be little contention in any case. Issue: SPR-8598
Rebased these changes into subversion trunk after review with Juergen. |
lks21c
added a commit
to lks21c/spring-framework-korean
that referenced
this pull request
Jan 3, 2015
itcrazy0717
added a commit
to itcrazy0717/spring-framework
that referenced
this pull request
Jun 6, 2018
#1.对spring源码进行测试,在spring-context模块中添加测试代码 spring-projects#2.对spring的bean生命周期进行调试,具体代码在spring-context模块中
Closed
This was referenced Jan 10, 2019
Issue SPR-368 (AOP proxy creation breaks property initialisation) not fixed in 1.1.2 [SPR-472]
#5201
Closed
Closed
This was referenced Jan 11, 2019
drodriguezhdez
referenced
this pull request
in scope-demo/spring-framework
Oct 14, 2019
This was referenced May 12, 2021
cesarhernandezgt
added a commit
to cesarhernandezgt/spring-framework
that referenced
this pull request
Mar 28, 2023
…ELEASE-TT.x-patch backport for CVE-2022-22970 and CVE-2022-22971
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Commit http://bit.ly/nXumTs ensured that component methods and fields
marked with 'common annotations' such as @resource, @PostConstruct and
@PreDestroy are invoked/assigned once and only once, even if multiple
instances of the CommonAnnotationBeanPostProcessor are processing the
same bean factory.
The implementation works against the InjectionMetadata API, adding and
removing these members from sets that track whether they are already
'externally managed', i.e. that another CABPP has already handled them,
thus avoiding redundant processing.
Prior to this change, the #remove operations against these sets were
not synchronized. In a single-threaded context this is fine thanks to
logic in AbstractAutowireCapableBeanFactory#doCreateBean that checks to
see whether a given bean definition has already been post processed.
However, as reported by SPR-8598, certain cases involving multiple
threads and annotated prototype-scoped beans can cause concurrent
modification exceptions during the #remove operation (ostensibly because
another thread is attempting to do the same removal at the same time,
though this has yet to be reproduced in isolation).
Now the sets originally introduced by the commit above are decorated
with Collections#synchronizedSet and any iterations over those sets
are synchronized properly. This change should have low performance
impact as such processing happens at container startup time (save for
non-singleton lookups at runtime), and there should be little
contention in any case.
Issue: SPR-8598