diff --git a/internal/store/builder.go b/internal/store/builder.go index 890550a355..954755133c 100644 --- a/internal/store/builder.go +++ b/internal/store/builder.go @@ -621,7 +621,16 @@ func (b *Builder) startReflector( instrumentedListWatch := watch.NewInstrumentedListerWatcher(listWatcher, b.listWatchMetrics, reflect.TypeOf(expectedType).String(), useAPIServerCache, objectLimit) reflector := cache.NewReflectorWithOptions(sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatch), expectedType, store, cache.ReflectorOptions{ResyncPeriod: 0}) if cr, ok := expectedType.(*unstructured.Unstructured); ok { - go reflector.Run((*b.GVKToReflectorStopChanMap)[cr.GroupVersionKind().String()]) + stopCh := make(chan struct{}) + gvkStopCh := (*b.GVKToReflectorStopChanMap)[cr.GroupVersionKind().String()] + go func() { + defer close(stopCh) + select { + case <-gvkStopCh: + case <-b.ctx.Done(): + } + }() + go reflector.Run(stopCh) } else { go reflector.Run(b.ctx.Done()) }