From a07e27082a1f0045a923bf6f26de113f472dd6a4 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Thu, 11 Aug 2022 22:22:40 -0700 Subject: [PATCH] Fix potential context leaking in scheduler --- pkg/scheduler/framework/preemption/preemption.go | 4 ++-- pkg/scheduler/framework/runtime/framework.go | 1 + pkg/scheduler/schedule_one.go | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/scheduler/framework/preemption/preemption.go b/pkg/scheduler/framework/preemption/preemption.go index 5f2c0933f36..19db5ee2c85 100644 --- a/pkg/scheduler/framework/preemption/preemption.go +++ b/pkg/scheduler/framework/preemption/preemption.go @@ -572,7 +572,7 @@ func (ev *Evaluator) DryRunPreemption(ctx context.Context, pod *v1.Pod, potentia fh := ev.Handler nonViolatingCandidates := newCandidateList(numCandidates) violatingCandidates := newCandidateList(numCandidates) - parallelCtx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(ctx) defer cancel() nodeStatuses := make(framework.NodeToStatusMap) var statusesLock sync.Mutex @@ -611,6 +611,6 @@ func (ev *Evaluator) DryRunPreemption(ctx context.Context, pod *v1.Pod, potentia nodeStatuses[nodeInfoCopy.Node().Name] = status statusesLock.Unlock() } - fh.Parallelizer().Until(parallelCtx, len(potentialNodes), checkNode) + fh.Parallelizer().Until(ctx, len(potentialNodes), checkNode) return append(nonViolatingCandidates.get(), violatingCandidates.get()...), nodeStatuses, utilerrors.NewAggregate(errs) } diff --git a/pkg/scheduler/framework/runtime/framework.go b/pkg/scheduler/framework/runtime/framework.go index e12ed28c875..c8db649b898 100644 --- a/pkg/scheduler/framework/runtime/framework.go +++ b/pkg/scheduler/framework/runtime/framework.go @@ -907,6 +907,7 @@ func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.Cy pluginToNodeScores[pl.Name()] = make(framework.NodeScoreList, len(nodes)) } ctx, cancel := context.WithCancel(ctx) + defer cancel() errCh := parallelize.NewErrorChannel() // Run Score method for each node in parallel. diff --git a/pkg/scheduler/schedule_one.go b/pkg/scheduler/schedule_one.go index 9d339048c02..0adf03388fb 100644 --- a/pkg/scheduler/schedule_one.go +++ b/pkg/scheduler/schedule_one.go @@ -476,6 +476,7 @@ func (sched *Scheduler) findNodesThatPassFilters( var statusesLock sync.Mutex var feasibleNodesLen int32 ctx, cancel := context.WithCancel(ctx) + defer cancel() checkNode := func(i int) { // We check the nodes starting from where we left off in the previous scheduling cycle, // this is to make sure all nodes have the same chance of being examined across pods.