diff --git a/pkg/controller/framework/shared_informer.go b/pkg/controller/framework/shared_informer.go index ce9ddf2c714..c557bf97548 100644 --- a/pkg/controller/framework/shared_informer.go +++ b/pkg/controller/framework/shared_informer.go @@ -279,21 +279,30 @@ func (p *processorListener) add(notification interface{}) { func (p *processorListener) pop(stopCh <-chan struct{}) { defer utilruntime.HandleCrash() - p.lock.Lock() - defer p.lock.Unlock() for { - for len(p.pendingNotifications) == 0 { - // check if we're shutdown - select { - case <-stopCh: - return - default: + blockingGet := func() (interface{}, bool) { + p.lock.Lock() + defer p.lock.Unlock() + + for len(p.pendingNotifications) == 0 { + // check if we're shutdown + select { + case <-stopCh: + return nil, true + default: + } + p.cond.Wait() } - p.cond.Wait() + nt := p.pendingNotifications[0] + p.pendingNotifications = p.pendingNotifications[1:] + return nt, false + } + + notification, stopped := blockingGet() + if stopped { + return } - notification := p.pendingNotifications[0] - p.pendingNotifications = p.pendingNotifications[1:] select { case <-stopCh: