Skip to content

Commit cd7a0ee

Browse files
authored
Merge pull request kubernetes#83945 from barkbay/fix-83895
Fix memory and timer leak in work queue
2 parents 57353d5 + f9c3d24 commit cd7a0ee

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

staging/src/k8s.io/client-go/util/workqueue/delaying_queue.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ func (q *delayingType) waitingLoop() {
178178
// Make a placeholder channel to use when there are no items in our list
179179
never := make(<-chan time.Time)
180180

181+
// Make a timer that expires when the item at the head of the waiting queue is ready
182+
var nextReadyAtTimer clock.Timer
183+
181184
waitingForQueue := &waitForPriorityQueue{}
182185
heap.Init(waitingForQueue)
183186

@@ -205,8 +208,12 @@ func (q *delayingType) waitingLoop() {
205208
// Set up a wait for the first item's readyAt (if one exists)
206209
nextReadyAt := never
207210
if waitingForQueue.Len() > 0 {
211+
if nextReadyAtTimer != nil {
212+
nextReadyAtTimer.Stop()
213+
}
208214
entry := waitingForQueue.Peek().(*waitFor)
209-
nextReadyAt = q.clock.After(entry.readyAt.Sub(now))
215+
nextReadyAtTimer = q.clock.NewTimer(entry.readyAt.Sub(now))
216+
nextReadyAt = nextReadyAtTimer.C()
210217
}
211218

212219
select {

0 commit comments

Comments
 (0)