-
Notifications
You must be signed in to change notification settings - Fork 650
[LSP] Fix data races on dirty state and script info version #897
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
[LSP] Fix data races on dirty state and script info version #897
Conversation
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 data race issues on dirty state and improvements to script info version usage by consolidating mutexes and reducing redundant method calls during file parsing.
- Replace multiple mutexes with a single mutex for project state.
- Remove redundant symlink-related method calls in script info.
- Cache script info version and text to avoid multiple evaluations.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
internal/project/scriptinfo.go | Removed redundant calls and eliminated an unused isSymlink function. |
internal/project/project.go | Consolidated mutexes and refactored logging based on updated file changes. |
internal/project/documentregistry.go | Cached script info version and text for consistent file parsing. |
Comments suppressed due to low confidence (3)
internal/project/scriptinfo.go:125
- Ensure that removing the symlink notification call aligns with the overall design and that any side effects previously handled by this call are now covered elsewhere.
project.onFileAddedOrRemoved(s.isSymlink())
internal/project/project.go:95
- [nitpick] Since the mutex now governs multiple aspects of project state, consider renaming 'mu' to something more descriptive (e.g., 'stateMu') to clarify its purpose.
mu sync.Mutex
internal/project/project.go:114
- While consolidating mutexes simplifies synchronization, verify that p.mu adequately protects the program field to avoid contention or race conditions previously managed by programMu.
programMu sync.Mutex
func (p *Project) onFileAddedOrRemoved(isSymlink bool) { | ||
p.dirtyStateMu.Lock() | ||
defer p.dirtyStateMu.Unlock() | ||
p.hasAddedOrRemovedFiles = true |
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.
These weren’t yet used for anything but logging, and they complicate the locking because they are sometimes, but not always, called during program construction when the mutex is already locked.
scriptInfoVersion := scriptInfo.Version() | ||
scriptInfoText := scriptInfo.Text() |
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.
Technically this should be one atomic access
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.
Do you want to address this now or later?
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.
I just tried protecting all the ScriptInfo fields with a mutex and accessing correlated fields within the same lock, but that had a ~20% penalty on project initialization
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.
I couldn't reproduce the issue before, but I tested and it still works for me, so 😄
scriptInfoVersion := scriptInfo.Version() | ||
scriptInfoText := scriptInfo.Text() |
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.
Do you want to address this now or later?
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.
I can confirm that this fixes the issue on Windows. 🎉
Changes
project
to operate with a single mutex, and avoids readingscriptInfo.Version()
multiple times during parsing.