]> git.feebdaed.xyz Git - 0xmirror/kubernetes.git/commitdiff
Fix data race in PriorityQueue.UnschedulablePods()
authorManuel Grandeit <m.grandeit@gmail.com>
Sat, 20 Dec 2025 12:34:01 +0000 (13:34 +0100)
committerManuel Grandeit <m.grandeit@gmail.com>
Sat, 20 Dec 2025 12:46:58 +0000 (13:46 +0100)
The UnschedulablePods() function iterates over the unschedulablePods.podInfoMap
without holding any lock, while other goroutines may concurrently modify the map
via addOrUpdate(), delete(), or clear().

Other functions like PendingPods() and GetPod() correctly acquire p.lock.RLock()
before accessing unschedulablePods.podInfoMap, but UnschedulablePods() was
missing this.

Fix by adding p.lock.RLock()/RUnlock() to UnschedulablePods(), matching the
pattern used by PendingPods().

pkg/scheduler/backend/queue/scheduling_queue.go

index 67004e115b894a829a4eae48a7f6e59dc102ca2b..2e9e5c09b3566c81936e3c0ca8185aa7c34c3663 100644 (file)
@@ -1302,6 +1302,8 @@ func (p *PriorityQueue) PodsInBackoffQ() []*v1.Pod {
 
 // UnschedulablePods returns all the pods in unschedulable state.
 func (p *PriorityQueue) UnschedulablePods() []*v1.Pod {
+       p.lock.RLock()
+       defer p.lock.RUnlock()
        var result []*v1.Pod
        for _, pInfo := range p.unschedulablePods.podInfoMap {
                result = append(result, pInfo.Pod)