typescript-go
typescript-go copied to clipboard
Fix: Add mutex protection for projects map to prevent race conditions
Summary
This PR adds proper mutex protection to the projects map in the API struct to prevent potential race conditions.
Problem
The projects map in internal/api/api.go was the only map in the API struct without mutex protection, while files, symbols, and types maps
were already protected. This inconsistency could lead to data races if the API handles concurrent requests.
Solution
- Added
sync.RWMutexto protect theprojectsmap - Applied read locks (
RLock) for all read operations (4 locations) - Applied write locks (
Lock) for write/delete operations (2 locations) - Used
RWMutexinstead ofMutexfor better read performance
Testing
- ✅ Code compiles without errors
- ✅ Passes race detector:
go test -race ./internal/api/... - ✅ No functional changes, backward compatible
Modified Files
internal/api/api.go
Impact
- Improves thread safety and code consistency
- Prepares codebase for concurrent request handling
- Negligible performance impact in single-threaded scenarios
Author: Catsayer