hub: stop sharing the embedded descriptor map across registries#632
Merged
Conversation
NewRegistryOfKnownResources and NewKVLocal wrapped resourcedescriptors.KnownDescriptors() — the package-global map — directly into a KVMap. Different Registry instances therefore held their own RWMutex but wrote into the same underlying Go map on KVMap.Set. The pool spins up one registry per cluster UID (PoolSize=1024); when several clusters concurrently discovered CRDs that weren't in the embedded set, those Set calls raced on the shared map. In Go that is a "fatal error: concurrent map writes" — not a silent corruption but a process crash. Introduce NewKVMapFromKnown(), which copies the known-descriptors map into a fresh map before wrapping it in a KVMap, and use it from both construction paths. KnownDescriptors() itself is unchanged; out-of-tree pool factories that share the global map should migrate to this helper. Signed-off-by: Tamal Saha <tamal@appscode.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
NewRegistryOfKnownResourcesandNewKVLocalboth wrappedresourcedescriptors.KnownDescriptors()— the package-global map — directly into aKVMap. EachRegistryheld its ownRWMutex, butKVMap.Setwrote into the same underlying Go map under different locks.PoolSize = 1024clusters, a CRD discovery from cluster A and one from cluster B can hitSetsimultaneously and trigger Go's runtimefatal error: concurrent map writes— a process crash, not silent corruption.NewKVMapFromKnown()which copies the map before wrapping, and use it from both in-tree construction sites.KnownDescriptors()is unchanged so out-of-tree consumers keep working; any pool factory that constructs aKVMapdirectly fromKnownDescriptors()should migrate to this helper.Test plan
make unit-testsgo test -race ./hub/...— exercise the registry concurrently via a small in-package test that spins multiple goroutines callingSeton different registries built fromNewRegistryOfKnownResources. (Optional follow-up if not yet present.)🤖 Generated with Claude Code