Skip to content

Commit ded2956

Browse files
authored
Merge pull request kubernetes#130886 from macsko/fix_race_when_closing_activeq
Fix a race when closing activeQ
2 parents 4b848a5 + 1be3f89 commit ded2956

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pkg/scheduler/backend/queue/active_queue.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ func (aq *activeQueue) done(pod types.UID) {
402402
aq.lock.Lock()
403403
defer aq.lock.Unlock()
404404

405+
aq.unlockedDone(pod)
406+
}
407+
408+
// unlockedDone is used by the activeQueue internally and doesn't take the lock itself.
409+
// It assumes the lock is already taken outside before the method is called.
410+
func (aq *activeQueue) unlockedDone(pod types.UID) {
405411
inFlightPod, ok := aq.inFlightPods[pod]
406412
if !ok {
407413
// This Pod is already done()ed.
@@ -446,15 +452,15 @@ func (aq *activeQueue) done(pod types.UID) {
446452

447453
// close closes the activeQueue.
448454
func (aq *activeQueue) close() {
455+
aq.lock.Lock()
456+
defer aq.lock.Unlock()
449457
// We should call done() for all in-flight pods to clean up the inFlightEvents metrics.
450458
// It's safe even if the binding cycle running asynchronously calls done() afterwards
451459
// done() will just be a no-op.
452460
for pod := range aq.inFlightPods {
453-
aq.done(pod)
461+
aq.unlockedDone(pod)
454462
}
455-
aq.lock.Lock()
456463
aq.closed = true
457-
aq.lock.Unlock()
458464
}
459465

460466
// broadcast notifies the pop() operation that new pod(s) was added to the activeQueue.

0 commit comments

Comments
 (0)