Guard shared maps in modelManager and config with locking#8
Open
phyceClaw wants to merge 1 commit into
Open
Conversation
Several readers iterated manager.Engines / entry.Models / config without holding the lock while writers mutated them under a write lock, causing data races and potential concurrent-map-iteration panics (notably in server mode). Add RLock to the affected readers, return copies of maps that escape, take the write lock in Import, and fix the unlock/relock-during-range in restartLocalEngines. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eliminates data races on shared maps that were read without the lock while other paths mutated them under a write lock (notably reachable in server mode).
modelManager:
GetEngineInstance,GetAllModels,GetAllEngines,GetModelVoices,GetInstanceCountnow hold the read lock while iteratingEngines/Models.restartLocalEnginesno longer unlocks/relocks in the middle of arange— it collects engine IDs under one lock, then restarts.config:
Get/GetSettings/GetModelToggles/GetEngineTogglesnow read under the lock and return copies of escaping maps.Importnow takes the write lock.Done conservatively to avoid deadlocks (unlocked inner helpers where methods call each other).
Testing
CGO_ENABLED=1 go build ./app/...passes;go vetclean.🤖 Generated with Claude Code