Skip to content

Fix data race and cache corruption in GetExternalMetric#1200

Merged
rsgowman merged 2 commits into
GoogleCloudPlatform:masterfrom
rsgowman:fix_external_metrics_cache
May 20, 2026
Merged

Fix data race and cache corruption in GetExternalMetric#1200
rsgowman merged 2 commits into
GoogleCloudPlatform:masterfrom
rsgowman:fix_external_metrics_cache

Conversation

@rsgowman
Copy link
Copy Markdown
Contributor

Only applicable when --external-metric-cache-ttl is enabled.

Previously, direct pointers to these objects were returned, which allows downstream handlers (e.g. transformResponseObject in k8s.io/apiserver) to mutate values in the cache, which can lead to a data race if two goroutines attempt to mutate it at the same time.

This fix returns a deep-copy instead, which allows the caller to mutate their copy without impacting the cached copy.

(Internal Google bug: http://b/511329740)

Only applicable when `--external-metric-cache-ttl` is enabled.

Previously, direct pointers to these objects were returned, which allows
downstream handlers (e.g. transformResponseObject in k8s.io/apiserver)
to mutate values in the cache, which can lead to a data race if two
goroutines attempt to mutate it at the same time.

This fix returns a deep-copy instead, which allows the caller to mutate
their copy without impacting the cached copy.

(Internal Google bug: http://b/511329740)
@rsgowman rsgowman requested a review from laoj2 May 20, 2026 18:36
Which is a much better location for this fix.

As suggested offline by laoj2@
@rsgowman rsgowman merged commit aeb7bde into GoogleCloudPlatform:master May 20, 2026
18 checks passed
@rsgowman rsgowman deleted the fix_external_metrics_cache branch May 20, 2026 22:01
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.

2 participants