Skip to content

Commit 593a2d4

Browse files
committed
Use buffered channel to prevent leak
1 parent bd510e1 commit 593a2d4

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

pkg/cache/internal/informers_map.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,14 @@ func (ip *specificInformersMap) Get(ctx context.Context, gvk schema.GroupVersion
164164
}
165165

166166
if started && !i.Informer.HasSynced() {
167-
syncReturn := make(chan bool)
168-
done := make(chan struct{})
167+
syncReturn := make(chan bool, 1 /* don't leak goroutines on timeout */)
169168
go func() {
170-
syncReturn <- cache.WaitForCacheSync(done, i.Informer.HasSynced)
169+
syncReturn <- cache.WaitForCacheSync(ctx.Done(), i.Informer.HasSynced)
171170
}()
172171

173172
// Wait for it to sync before returning the Informer so that folks don't read from a stale cache.
174173
select {
175174
case <-ctx.Done():
176-
//end the polling for cache to sync
177-
done <- struct{}{}
178175
return started, nil, apierrors.NewTimeoutError(fmt.Sprintf("timeout waiting for %T Informer to sync", obj), 0)
179176
case syncSuccess := <-syncReturn:
180177
if !syncSuccess {

0 commit comments

Comments
 (0)