Skip to content

Commit d614d05

Browse files
committed
Ensure GetWithPriority does not block after queue shutdown
1 parent 2d909e6 commit d614d05

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pkg/controller/priorityqueue/priorityqueue.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,15 @@ func (w *priorityqueue[T]) GetWithPriority() (_ T, priority int, shutdown bool)
290290

291291
w.notifyItemOrWaiterAdded()
292292

293-
item := <-w.get
294-
295-
return item.Key, item.Priority, w.shutdown.Load()
293+
select {
294+
case <-w.done:
295+
// Return if the queue was shutdown to avoid blocking callers, e.g. this would block controller workers
296+
// during controller shutdown otherwise because they are stuck in GetWithPriority().
297+
var zero T
298+
return zero, 0, true
299+
case item := <-w.get:
300+
return item.Key, item.Priority, w.shutdown.Load()
301+
}
296302
}
297303

298304
func (w *priorityqueue[T]) Get() (item T, shutdown bool) {

0 commit comments

Comments
 (0)