APIGOV-DG000 Fix concurrent map iteration/write race in cache Get methods - #1067
Merged
Conversation
Every Get*/List* method in pkg/agent/cache called CreateHashes() on the resource pointer stored in the cache while holding only a read lock. CreateHashes mutates SubResourceHashes in place with no synchronization of its own, so concurrent Get calls (or a Get racing a read of the same resource elsewhere, e.g. a model's FromInstance ranging over SubResourceHashes) could hit Go's "concurrent map iteration and map write" fatal error - reproduced in production by an agent processing resources via parallel goroutines against the shared cache. Add withComputedHashes, which returns a shallow copy with freshly computed hashes instead of mutating the cached pointer, and use it at every such call site. Includes TestConcurrentGetsDoNotRace as a regression test (passes cleanly under -race). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
dgghinea
requested review from
alrosca,
dfeldick,
jcollins-axway,
sbolosan and
vivekschauhan
as code owners
July 27, 2026 12:54
vivekschauhan
approved these changes
Jul 27, 2026
jcollins-axway
approved these changes
Jul 27, 2026
sbolosan
approved these changes
Aug 5, 2026
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.
Every Get*/List* method in pkg/agent/cache called CreateHashes() on the resource pointer stored in the cache while holding only a read lock. CreateHashes mutates SubResourceHashes in place with no synchronization of its own, so concurrent Get calls (or a Get racing a read of the same resource elsewhere, e.g. a model's FromInstance ranging over SubResourceHashes) could hit Go's "concurrent map iteration and map write" fatal error - reproduced in production by an agent processing resources via parallel goroutines against the shared cache.
Add withComputedHashes, which returns a shallow copy with freshly computed hashes instead of mutating the cached pointer, and use it at every such call site. Includes TestConcurrentGetsDoNotRace as a regression test (passes cleanly under -race).