Skip to content

[release-0.21] 🐛 Priorityqueue: Don't block on Get when queue is shutdown #3245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/controller/priorityqueue/priorityqueue.go
Original file line number Diff line number Diff line change
@@ -277,6 +277,13 @@ 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
}

item := <-w.get

return item.Key, item.Priority, w.shutdown.Load()
20 changes: 20 additions & 0 deletions pkg/controller/priorityqueue/priorityqueue_test.go
Original file line number Diff line number Diff line change
@@ -300,6 +300,26 @@ var _ = Describe("Controllerworkqueue", func() {
Expect(metrics.depth["test"]).To(Equal(map[int]int{0: 2}))
})

// ref: https://github.com/kubernetes-sigs/controller-runtime/issues/3239
It("Get from priority queue might get stuck when the priority queue is shut down", func() {
q, _ := newQueue()

q.Add("baz")
// shut down
q.ShutDown()
q.AddWithOpts(AddOpts{After: time.Second}, "foo")

item, priority, isShutDown := q.GetWithPriority()
Expect(item).To(Equal(""))
Expect(priority).To(Equal(0))
Expect(isShutDown).To(BeTrue())

item1, priority1, isShutDown := q.GetWithPriority()
Expect(item1).To(Equal(""))
Expect(priority1).To(Equal(0))
Expect(isShutDown).To(BeTrue())
})

It("items are included in Len() and the queueDepth metric once they are ready", func() {
q, metrics := newQueue()
defer q.ShutDown()