Skip to content

Commit 9cff5f0

Browse files
committed
Use buffered channel to prevent leak
1 parent 30956a6 commit 9cff5f0

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
@@ -182,17 +182,14 @@ func (ip *specificInformersMap) Get(ctx context.Context, gvk schema.GroupVersion
182182
}
183183

184184
if started && !i.Informer.HasSynced() {
185-
syncReturn := make(chan bool)
186-
done := make(chan struct{})
185+
syncReturn := make(chan bool, 1 /* don't leak goroutines on timeout */)
187186
go func() {
188-
syncReturn <- cache.WaitForCacheSync(done, i.Informer.HasSynced)
187+
syncReturn <- cache.WaitForCacheSync(ctx.Done(), i.Informer.HasSynced)
189188
}()
190189

191190
// Wait for it to sync before returning the Informer so that folks don't read from a stale cache.
192191
select {
193192
case <-ctx.Done():
194-
//end the polling for cache to sync
195-
done <- struct{}{}
196193
return started, nil, apierrors.NewTimeoutError(fmt.Sprintf("timeout waiting for %T Informer to sync", obj), 0)
197194
case syncSuccess := <-syncReturn:
198195
if !syncSuccess {

0 commit comments

Comments
 (0)