Skip to content
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

Atomic operations for BeanDefinitionProducer #11570

Open
wants to merge 3 commits into
base: 4.8.x
Choose a base branch
from

Conversation

yawkat
Copy link
Member

@yawkat yawkat commented Feb 5, 2025

Replace the BeanDefinitionProducer API with atomic operations. This removes patterns like if (producer.isReferenceEnabled()) producer.getReference() which could cause TOCTOU concurrency issues.

Should fix #11569

Replace the BeanDefinitionProducer API with atomic operations. This removes patterns like `if (producer.isReferenceEnabled()) producer.getReference()` which could cause TOCTOU concurrency issues.

Should fix #11569
@yawkat yawkat added the type: bug Something isn't working label Feb 5, 2025
@yawkat yawkat added this to the 4.8.0 milestone Feb 5, 2025
Copy link
Contributor

@mikehearn mikehearn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK though it'd be good to have a comment justifying this sort of very fine grained parallelism with performance numbers. There are some unintuitive states possible here (e.g. reference == null whilst definition is not the sentinel). I can see why bean management would be performance sensitive, but how much difference does all this really make?

@@ -2078,7 +2080,7 @@ protected void initializeContext(
if (CollectionUtils.isNotEmpty(parallelBeans)) {
processParallelBeans(parallelBeans);
}
ForkJoinPool.commonPool().execute(() -> beanDefinitionsClasses.forEach(p -> p.isReferenceEnabled(this)));
ForkJoinPool.commonPool().execute(() -> beanDefinitionsClasses.forEach(p -> p.getReferenceIfEnabled(this)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this line trying to do originally? It looks a bit odd.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's kicking off async loading of all bean definitions that were not initialized by the previous code

Copy link
Contributor

@sdelamo sdelamo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have tests for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Race condition in DefaultBeanContext.BeanDefinitionProducer
3 participants