Skip to content

APIGOV-DG000 Fix concurrent map iteration/write race in cache Get methods - #1067

Merged
dgghinea merged 1 commit into
mainfrom
APIGOV-DG000
Aug 5, 2026
Merged

APIGOV-DG000 Fix concurrent map iteration/write race in cache Get methods#1067
dgghinea merged 1 commit into
mainfrom
APIGOV-DG000

Conversation

@dgghinea

Copy link
Copy Markdown
Collaborator

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).

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 dgghinea changed the title Fix concurrent map iteration/write race in cache Get methods APIGOV-DG000 Fix concurrent map iteration/write race in cache Get methods Jul 27, 2026
@dgghinea
dgghinea merged commit 8a53835 into main Aug 5, 2026
2 checks passed
@dgghinea
dgghinea deleted the APIGOV-DG000 branch August 5, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants