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

fix: locking on FeatureFlags instead of VaadinContext (#13962) #14741

Merged
merged 3 commits into from
Oct 17, 2022

Conversation

MarcinVaadin
Copy link
Member

@MarcinVaadin MarcinVaadin commented Oct 5, 2022

Description

Potential solutions (I did not really think these through):

Lock on vaadin context in getCachedIndexHtmlDocument to avoid locking in another order. Seems quite fragile and there might be other similar cases here and there.
Use the same object for locking in all cases. Can't see why we really need to synchronize on different ones for these operations

Only lock on FeatureFlags when checking for wrapper and initializing

Fixes #13962

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

@MarcinVaadin MarcinVaadin linked an issue Oct 5, 2022 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Oct 5, 2022

Unit Test Results

   955 files  ±  0     955 suites  ±0   58m 2s ⏱️ + 4m 6s
6 082 tests ±  0  6 028 ✔️ ±  0  54 💤 ±0  0 ±0 
6 348 runs  +11  6 286 ✔️ +11  62 💤 ±0  0 ±0 

Results for commit 9111842. ± Comparison against base commit dc00ef1.

♻️ This comment has been updated with latest results.

@Artur-
Copy link
Member

Artur- commented Oct 5, 2022

Is VaadinServletContext a singleton? Otherwise locking will have no effect

@MarcinVaadin MarcinVaadin marked this pull request as draft October 5, 2022 12:37
@MarcinVaadin
Copy link
Member Author

MarcinVaadin commented Oct 5, 2022

Is VaadinServletContext a singleton? Otherwise locking will have no effect

@Artur- indeed, so why to lock on VaadinContext in FeatureFlags if they call setAttributes which already locks on ServletContext?

@Artur-
Copy link
Member

Artur- commented Oct 6, 2022

The locking in FeatureFlags looks wrong. It wants to lock to avoid creating FeatureFlagsWrapper multiple times. The normal pattern for that would be something like

FeatureFlagsWrapper attribute = context.getAttribute(FeatureFlagsWrapper.class);
if (attribute == null) {
  synchronized (FeatureFlags.class) {
    attribute = context.getAttribute(FeatureFlagsWrapper.class);
    if (attribute == null) {
        // create it
    }
  }
}
return attribute.getFeatureFlags();

There is no need to lock on anything external as only FeatureFlags is creating the wrapper.

The simpler version which locks every time, and might be good enough in FeatureFlags would be

synchronized (FeatureFlags.class) {
  FeatureFlagsWrapper attribute = context.getAttribute(FeatureFlagsWrapper.class);
  if (attribute == null) {
      // create it
  }
}
return attribute.getFeatureFlags();

@sonarcloud
Copy link

sonarcloud bot commented Oct 6, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@Artur- Artur- left a comment

Choose a reason for hiding this comment

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

Looks good to me but the fix does not correspond at all with the summary or description

@MarcinVaadin MarcinVaadin marked this pull request as ready for review October 12, 2022 08:45
@caalador caalador changed the title fix: set locking to VaadinContext instead of ServletContext (#13962) fix: locking on FeatureFlags instead of VaadinContext (#13962) Oct 17, 2022
@caalador caalador merged commit 6950d57 into master Oct 17, 2022
OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Iteration Reviews to Done - pending release Oct 17, 2022
@caalador caalador deleted the fix/13962-deadlock-after-restart branch October 17, 2022 06:14
vaadin-bot pushed a commit that referenced this pull request Oct 17, 2022
Only lock on FeatureFlags when checking for wrapper and initializing

Fixes #13962
vaadin-bot pushed a commit that referenced this pull request Oct 17, 2022
Only lock on FeatureFlags when checking for wrapper and initializing

Fixes #13962
vaadin-bot pushed a commit that referenced this pull request Oct 17, 2022
Only lock on FeatureFlags when checking for wrapper and initializing

Fixes #13962
caalador pushed a commit that referenced this pull request Oct 17, 2022
… (#14860)

Only lock on FeatureFlags when checking for wrapper and initializing

Fixes #13962

Co-authored-by: marcin <marcin@vaadin.com>
caalador pushed a commit that referenced this pull request Oct 17, 2022
… (#14861)

Only lock on FeatureFlags when checking for wrapper and initializing

Fixes #13962

Co-authored-by: marcin <marcin@vaadin.com>
caalador pushed a commit that referenced this pull request Oct 17, 2022
… (#14862)

Only lock on FeatureFlags when checking for wrapper and initializing

Fixes #13962

Co-authored-by: marcin <marcin@vaadin.com>
TatuLund added a commit that referenced this pull request Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
OLD Vaadin Flow ongoing work (Vaadin ...
  
Done - pending release
Development

Successfully merging this pull request may close these issues.

Deadlock after restart
4 participants