Skip to content

Commit 7f16f2b

Browse files
committed
Copy object before modifying it
Otherwise you can get races when getting and listing simultaneously
1 parent bab2dad commit 7f16f2b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pkg/cache/internal/cache_reader.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ func (c *CacheReader) List(_ context.Context, out runtime.Object, opts ...client
125125
if !isObj {
126126
return fmt.Errorf("cache contained %T, which is not an Object", obj)
127127
}
128-
obj.GetObjectKind().SetGroupVersionKind(c.groupVersionKind)
129-
runtimeObjs = append(runtimeObjs, obj)
128+
outObj := obj.DeepCopyObject()
129+
outObj.GetObjectKind().SetGroupVersionKind(c.groupVersionKind)
130+
runtimeObjs = append(runtimeObjs, outObj)
130131
}
131132
filteredItems, err := objectutil.FilterWithLabels(runtimeObjs, labelSel)
132133
if err != nil {

0 commit comments

Comments
 (0)