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

Merged
merged 3 commits into from
Feb 7, 2025
Merged

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?

@dstepanov
Copy link
Contributor

Is it going to affect the startup performance?

@yawkat
Copy link
Member Author

yawkat commented Feb 6, 2025

@sdelamo i don't know how to reproduce the original bug, it's some weird race condition

@yawkat
Copy link
Member Author

yawkat commented Feb 6, 2025

@dstepanov I think it should be no worse than before, there's no additional locks or extra work. maybe it's even slightly faster

@sdelamo
Copy link
Contributor

sdelamo commented Feb 7, 2025

@dstepanov If you are ok with this, lets merge it and release 4.8.1 core

@dstepanov dstepanov merged commit c89693a into 4.8.x Feb 7, 2025
22 checks passed
@dstepanov dstepanov deleted the concurrent-producer branch February 7, 2025 18:16
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: Done
Development

Successfully merging this pull request may close these issues.

Race condition in DefaultBeanContext.BeanDefinitionProducer
4 participants