Skip to content

Commit 4c2e9ce

Browse files
authored
Merge pull request #3250 from alvaroaleman/shutdown
🐛 Priorityqueue: Shutdown on shutdown
2 parents 4bf6ec1 + b43c1ad commit 4c2e9ce

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pkg/controller/priorityqueue/priorityqueue.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ type priorityqueue[T comparable] struct {
129129
}
130130

131131
func (w *priorityqueue[T]) AddWithOpts(o AddOpts, items ...T) {
132+
if w.shutdown.Load() {
133+
return
134+
}
135+
132136
w.lock.Lock()
133137
defer w.lock.Unlock()
134138

@@ -274,16 +278,15 @@ func (w *priorityqueue[T]) AddRateLimited(item T) {
274278
}
275279

276280
func (w *priorityqueue[T]) GetWithPriority() (_ T, priority int, shutdown bool) {
277-
w.waiters.Add(1)
278-
279-
w.notifyItemOrWaiterAdded()
280-
281-
// ref: https://github.com/kubernetes-sigs/controller-runtime/issues/3239
282281
if w.shutdown.Load() {
283282
var zero T
284283
return zero, 0, true
285284
}
286285

286+
w.waiters.Add(1)
287+
288+
w.notifyItemOrWaiterAdded()
289+
287290
item := <-w.get
288291

289292
return item.Key, item.Priority, w.shutdown.Load()

0 commit comments

Comments
 (0)