diff --git a/pkg/search/proxy/store/multi_cluster_cache.go b/pkg/search/proxy/store/multi_cluster_cache.go index 292abc978..ef97ae906 100644 --- a/pkg/search/proxy/store/multi_cluster_cache.go +++ b/pkg/search/proxy/store/multi_cluster_cache.go @@ -315,7 +315,6 @@ func (c *MultiClusterCache) Watch(ctx context.Context, gvr schema.GroupVersionRe } mux.AddSource(w, func(e watch.Event) { - // We can safely modify data because it is deepCopied in cacheWatcher.convertToWatchEvent setObjectResourceVersionFunc(cluster, e.Object) addCacheSourceAnnotation(e.Object, cluster) }) diff --git a/pkg/search/proxy/store/util.go b/pkg/search/proxy/store/util.go index d52d7fb0f..0333557a6 100644 --- a/pkg/search/proxy/store/util.go +++ b/pkg/search/proxy/store/util.go @@ -214,15 +214,16 @@ func (w *watchMux) startWatchSource(source watch.Interface, decorator func(watch defer source.Stop() defer w.Stop() for { - var event watch.Event - var ok bool + var copyEvent watch.Event select { - case event, ok = <-source.ResultChan(): + case sourceEvent, ok := <-source.ResultChan(): if !ok { return } + // sourceEvent object is cacheObject,all watcher use the same point,must deepcopy. + copyEvent = *sourceEvent.DeepCopy() if decorator != nil { - decorator(event) + decorator(copyEvent) } case <-w.done: return @@ -241,7 +242,7 @@ func (w *watchMux) startWatchSource(source watch.Interface, decorator func(watch case <-w.done: return default: - w.result <- event + w.result <- copyEvent } }() }