Merge pull request #130886 from macsko/fix_race_when_closing_activeq

Fix a race when closing activeQ
This commit is contained in:
Kubernetes Prow Robot 2025-03-18 06:32:07 -07:00 committed by GitHub
commit ded2956c83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -402,6 +402,12 @@ func (aq *activeQueue) done(pod types.UID) {
aq.lock.Lock()
defer aq.lock.Unlock()
aq.unlockedDone(pod)
}
// unlockedDone is used by the activeQueue internally and doesn't take the lock itself.
// It assumes the lock is already taken outside before the method is called.
func (aq *activeQueue) unlockedDone(pod types.UID) {
inFlightPod, ok := aq.inFlightPods[pod]
if !ok {
// This Pod is already done()ed.
@ -446,15 +452,15 @@ func (aq *activeQueue) done(pod types.UID) {
// close closes the activeQueue.
func (aq *activeQueue) close() {
aq.lock.Lock()
defer aq.lock.Unlock()
// We should call done() for all in-flight pods to clean up the inFlightEvents metrics.
// It's safe even if the binding cycle running asynchronously calls done() afterwards
// done() will just be a no-op.
for pod := range aq.inFlightPods {
aq.done(pod)
aq.unlockedDone(pod)
}
aq.lock.Lock()
aq.closed = true
aq.lock.Unlock()
}
// broadcast notifies the pop() operation that new pod(s) was added to the activeQueue.