-
Notifications
You must be signed in to change notification settings - Fork 749
Fix: Add mutex protection for projects map to prevent race conditions #2251
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: main
Are you sure you want to change the base?
Conversation
The projects map in the API struct was missing concurrency protection
while other maps (files, symbols, types) were already protected by
mutexes. This inconsistency could lead to race conditions if the API
is used concurrently in the future.
Changes:
- Add sync.RWMutex to protect projects map
- Use RLock/RUnlock for read operations (GetSymbolAtPosition,
GetSymbolAtLocation, GetTypeOfSymbol, GetSourceFile)
- Use Lock/Unlock for write operations (LoadProject, releaseHandle)
This change maintains consistency with existing code patterns and
prepares the codebase for potential concurrent request handling.
Author: Catsayer
|
@Catsayer-Chan please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
|
@microsoft-github-policy-service agree |
Summary
This PR adds proper mutex protection to the
projectsmap in the API struct to prevent potential race conditions.Problem
The
projectsmap ininternal/api/api.gowas the only map in the API struct without mutex protection, whilefiles,symbols, andtypesmapswere already protected. This inconsistency could lead to data races if the API handles concurrent requests.
Solution
sync.RWMutexto protect theprojectsmapRLock) for all read operations (4 locations)Lock) for write/delete operations (2 locations)RWMutexinstead ofMutexfor better read performanceTesting
go test -race ./internal/api/...Modified Files
internal/api/api.goImpact
Author: Catsayer