From 04e9340ab42b58ff25862599a2935b8128363bbe Mon Sep 17 00:00:00 2001 From: Craig Condit Date: Mon, 23 Oct 2023 18:36:03 -0500 Subject: [PATCH] [YUNIKORN-2068] Fix deadlock when evaluating preemption candidates (#697) Closes: #697 --- pkg/cache/context.go | 2 +- pkg/cache/external/scheduler_cache.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/cache/context.go b/pkg/cache/context.go index d3488bc10..a255e78d6 100644 --- a/pkg/cache/context.go +++ b/pkg/cache/context.go @@ -474,7 +474,7 @@ func (ctx *Context) IsPodFitNodeViaPreemption(name, node string, allocations []s // look up each victim in the scheduler cache victims := make([]*v1.Pod, 0) for _, uid := range allocations { - if victim, ok := ctx.schedulerCache.GetPod(uid); ok { + if victim, ok := ctx.schedulerCache.GetPodNoLock(uid); ok { victims = append(victims, victim) } else { // if pod isn't found, add a placeholder so that the list is still the same size diff --git a/pkg/cache/external/scheduler_cache.go b/pkg/cache/external/scheduler_cache.go index 3a4434e74..aaf063f51 100644 --- a/pkg/cache/external/scheduler_cache.go +++ b/pkg/cache/external/scheduler_cache.go @@ -471,6 +471,10 @@ func (cache *SchedulerCache) removePod(pod *v1.Pod) { func (cache *SchedulerCache) GetPod(uid string) (*v1.Pod, bool) { cache.lock.RLock() defer cache.lock.RUnlock() + return cache.GetPodNoLock(uid) +} + +func (cache *SchedulerCache) GetPodNoLock(uid string) (*v1.Pod, bool) { if pod, ok := cache.podsMap[uid]; ok { return pod, true }