From b43c1ad5a9ace6004f4255bd12168a2609da6b80 Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Sat, 28 Jun 2025 12:35:34 -0400 Subject: [PATCH] :bug: Priorityqueue: Shutdown on shutdown The PQ still stores new items when shutdown and triggers processing when Get is called, avoid all of that. --- pkg/controller/priorityqueue/priorityqueue.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/controller/priorityqueue/priorityqueue.go b/pkg/controller/priorityqueue/priorityqueue.go index 3f18918d4d..1f1a245849 100644 --- a/pkg/controller/priorityqueue/priorityqueue.go +++ b/pkg/controller/priorityqueue/priorityqueue.go @@ -129,6 +129,10 @@ type priorityqueue[T comparable] struct { } func (w *priorityqueue[T]) AddWithOpts(o AddOpts, items ...T) { + if w.shutdown.Load() { + return + } + w.lock.Lock() defer w.lock.Unlock() @@ -274,16 +278,15 @@ func (w *priorityqueue[T]) AddRateLimited(item T) { } func (w *priorityqueue[T]) GetWithPriority() (_ T, priority int, shutdown bool) { - w.waiters.Add(1) - - w.notifyItemOrWaiterAdded() - - // ref: https://github.com/kubernetes-sigs/controller-runtime/issues/3239 if w.shutdown.Load() { var zero T return zero, 0, true } + w.waiters.Add(1) + + w.notifyItemOrWaiterAdded() + item := <-w.get return item.Key, item.Priority, w.shutdown.Load()