@@ -533,10 +533,14 @@ func (c *Impl) processNextWorkItem() bool {
533533}
534534
535535func (c * Impl ) handleErr (logger * zap.SugaredLogger , err error , key types.NamespacedName , startTime time.Time ) {
536- if IsSkipKey (err ) {
536+ // Check if we should skip this key or if the queue is shutting down.
537+ // We check shutdown here since controller Run might have exited by now
538+ // (since while this item was being processed, queue.Len==0).
539+ if IsSkipKey (err ) || c .workQueue .ShuttingDown () {
537540 c .workQueue .Forget (key )
538541 return
539542 }
543+
540544 if ok , delay := IsRequeueKey (err ); ok {
541545 c .workQueue .AddAfter (key , delay )
542546 logger .Debugf ("Requeuing key %s (by request) after %v (depth: %d)" , safeKey (key ), delay , c .workQueue .Len ())
@@ -553,10 +557,7 @@ func (c *Impl) handleErr(logger *zap.SugaredLogger, err error, key types.Namespa
553557 logger .Errorw ("Reconcile error" , zap .Duration ("duration" , time .Since (startTime )), zap .Error (err ))
554558
555559 // Re-queue the key if it's a transient error.
556- // We want to check that the queue is shutting down here
557- // since controller Run might have exited by now (since while this item was
558- // being processed, queue.Len==0).
559- if ! IsPermanentError (err ) && ! c .workQueue .ShuttingDown () {
560+ if ! IsPermanentError (err ) {
560561 c .workQueue .AddRateLimited (key )
561562 logger .Debugf ("Requeuing key %s due to non-permanent error (depth: %d)" , safeKey (key ), c .workQueue .Len ())
562563 return
0 commit comments