-
Notifications
You must be signed in to change notification settings - Fork 167
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
fix: prevent deadlock when accessing FeatureFlags #17645
Conversation
Synchronizing over FeatureFlags class in FeatureFlags.get could lead to a deadlock when the call comes from a supplier provided to VaadinContext.getAttribute() and concurrently from another request. For example, in the linked issue: - thread A invokes IndexHtmlRequestHandler.getCachedIndexHtmlDocument(), that locks the ServletContext through VaadinContext.getAttribute(...) providing a supplier that calls FeatureFlags.get() - thread B concurrently executes IndexHtmlRequestHandler.getIndexHtmlDocument() that also calls FeatureFlags.get() that locks on FeaturFlags class When B invokes FeatureFlags.get() -> VaadinContext.getAttribute() it has to wait because ServletContext is already locked A, but A is calling FeatureFlags.get() and it is waiting to lock on FeatureFlags class. This change removes the synchronization on FeatureFlags class and relies on VaadinContext.getAttribute(Class, Supplier) internal synchronization to prevent FeatureFlag two be instanciated more than once. It also adds test to ensure there are no regressions for #13962. Fixes #17637
Are these new tests supposed to fail without this fix? When I run new tests without the fix, tests passed unexpectedly. Also when I added the test from the issue #17637 in |
Without the fix,
The test in the issue should be the same as |
Now I see. If you added the test to
You should add whenComplete( ((unused, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
}
}) |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
This ticket/PR has been released with Vaadin 24.2.0.beta1 and is also targeting the upcoming stable 24.2.0 version. |
Description
Synchronizing over FeatureFlags class in FeatureFlags.get could lead to a deadlock when the call comes from a supplier provided to VaadinContext.getAttribute() and concurrently from another request.
For example, in the linked issue:
When B invokes FeatureFlags.get() -> VaadinContext.getAttribute() it has to wait because ServletContext is already locked A, but A is calling FeatureFlags.get() and it is waiting to lock on FeatureFlags class.
This change removes the synchronization on FeatureFlags class and relies on VaadinContext.getAttribute(Class, Supplier) internal synchronization to prevent FeatureFlag two be instanciated more than once.
It also adds test to ensure there are no regressions for #13962.
Fixes #17637
Type of change
Checklist
Additional for
Feature
type of change