Skip to content

Commit cfdef09

Browse files
authored
Fix linear cache data race (#502)
Signed-off-by: Andrew Stucki <[email protected]>
1 parent 348b178 commit cfdef09

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/cache/v3/linear.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,14 @@ func (cache *LinearCache) SetResources(resources map[string]types.Resource) {
250250
func (cache *LinearCache) GetResources() map[string]types.Resource {
251251
cache.mu.RLock()
252252
defer cache.mu.RUnlock()
253-
return cache.resources
253+
254+
// create a copy of our internal storage to avoid data races
255+
// involving mutations of our backing map
256+
resources := make(map[string]types.Resource, len(cache.resources))
257+
for k, v := range cache.resources {
258+
resources[k] = v
259+
}
260+
return resources
254261
}
255262

256263
func (cache *LinearCache) CreateWatch(request *Request, value chan Response) func() {

0 commit comments

Comments
 (0)