-
Notifications
You must be signed in to change notification settings - Fork 226
Fix for multi threading issues in AnnotationMap #3397
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
base: master
Are you sure you want to change the base?
Fix for multi threading issues in AnnotationMap #3397
Conversation
@mehmet-karaman can you please more explain the rationale behind the changes? I think we can assume code is there for a reason so if we change fundamental things we should carefully describe the reasons and causes and why it is not a bug of the caller for example as otherwise we might run into deadlocks if code that previously run outside locks now run under lock conditions. |
The change here is coming from eclipse-xtext/xtext#3524 investigation. |
@szarnekow : if you have time, would be good if you could check this PR. |
It still would be good to more explain the individual changes and why they are required / needed. Also I think some changes are better a separate PR (as they are easier to review then e.g. "Removed dead code" or API documentation enhancements) |
Could you please point which exactly? |
Each of those can be an own PR
All of these seem independent and local enough to be quickly reviewed and merged and likely will improve things without risk for regression. And even if they are easier to revert in isolation. Then might be the next thing
and finally
This will make each PR small, focused and likely better to understand the implications and its easier to write a concise commit message. |
bundles/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java
Outdated
Show resolved
Hide resolved
I believe these could be seperated from the main PR, but should go in one PR, because they all require each other. |
Sure at laest I think these are more "cleanup" and currently make the PR harder to review than it should. |
Test Results 3 018 files ±0 3 018 suites ±0 2h 28m 55s ⏱️ + 7m 28s For more details on these failures, see this check. Results for commit 5fa4d84. ± Comparison against base commit 554e227. ♻️ This comment has been updated with latest results. |
34fc4f0
to
4082003
Compare
I've rebased on #3399 state, fixed merge conflicts & my own comment above. |
f3ef6e9
to
e5d2191
Compare
Test failures on Windows are unrelated. @mehmet-karaman, @laeubi : please feel free to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks ok in general but I have not testes it.
bundles/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java
Show resolved
Hide resolved
e5d2191
to
703a1ad
Compare
Resolved two remaining comments and rebased on latest master. |
@mehmet-karaman : you have now two commits, I assume by mistake. Can you please have one? |
- added synchronize block to methods in AnnotationModel, wherever reads / writes could happen in multiple threads. - changed execution order, to be able to synchronize only necessary code blocks. Co-authored-by: Andrey Loskutov <loskutov@gmx.de>
703a1ad
to
5fa4d84
Compare
squashed the two commits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses multithreading issues in the AnnotationModel class by adding proper synchronization to prevent race conditions during concurrent access to annotation data. The changes ensure thread safety while maintaining performance by minimizing the scope of synchronized blocks.
Key changes:
- Added synchronized blocks around critical sections that access shared data structures
- Reorganized execution order to minimize time spent in synchronized blocks
- Removed dead code and added validation checks
if (fireModelChanged && forkNotification) { | ||
removeAnnotations(deleted, false, false); | ||
synchronized (getLockObject()) { | ||
synchronized (mapLock) { |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'mapLock' directly instead of 'getLockObject()' is inconsistent with the synchronization pattern used throughout the rest of the class. This should use 'getLockObject()' for consistency and to ensure the same lock object is used.
synchronized (mapLock) { | |
synchronized (annotations.getLockObject()) { |
Copilot uses AI. Check for mistakes.
IDocument document= fDocument; | ||
if (document != null) { | ||
for (int i= 0; i < fOpenConnections; i++) { | ||
ret.disconnect(fDocument); |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'fDocument' instead of the local 'document' variable creates a potential race condition. The local 'document' variable was captured to avoid accessing the field multiple times, but this line still uses the field directly.
ret.disconnect(fDocument); | |
ret.disconnect(document); |
Copilot uses AI. Check for mistakes.
Uh oh!
There was an error while loading. Please reload this page.