Bug: Potential concurrent access to shared session statement `stmt` in `DryRunPreemption` → `SelectVictimsOnNode`
Description
In pkg/scheduler/actions/preempt/preempt.go, the DryRunPreemption function passes the shared, live session statement (stmt) into worker goroutines via SelectVictimsOnNode.
While the stateLock correctly guards nodeStatuses, and concurrent access to the session state uses stateCopy := state.Clone(), the stmt object itself may be accessed concurrently by worker goroutines that assume it to be read-only.
Inside SelectVictimsOnNode, the same stmt instance is passed to plugin callbacks. These callbacks may mutate the statement (e.g., via stmt.Evict(...)) without synchronization.
Since DryRunPreemption is intended to simulate preemption without committing side effects, sharing a mutable stmt across goroutines may lead to unintended state mutation or inconsistent behavior during concurrent execution.
Steps to reproduce the issue
- Run the Volcano scheduler under a load that triggers scheduling preemption.
- In
pkg/scheduler/actions/preempt/preempt.go, observeDryRunPreemptionpassing the livestmtinto parallel workers managed byworkqueue.ParallelizeUntil. - Within the workers,
SelectVictimsOnNodepassesstmtinto simulation paths and plugin callbacks. - Tracing down, plugins invoke
stmt.Evict(...)(or similar statement-modifying functions). - Observe that multiple goroutines may access and modify the shared
stmtobject concurrently during the dry-run execution.
Describe the results you received and expected
Results received:
The shared stmt object appears to be accessed and potentially mutated concurrently by multiple goroutines during DryRunPreemption. This may lead to data races, and dry-run evictions could be accumulated into the live statement without proper synchronization, affecting the actual preemption state.
Expected results:
DryRunPreemption should have no side effects on the actual session statement. The stmt path should either be avoided in DryRunPreemption and SelectVictimsOnNode, or the dry run should instantiate and pass a fresh, per-goroutine throwaway statement that is safely discarded after simulation.
What version of Volcano are you using?
master / latest
Any other relevant information
Suggested Fix:
One possible approach is to avoid sharing the live stmt across goroutines in the DryRunPreemption → SelectVictimsOnNode path.
Instead, DryRunPreemption could initialize a fresh, per-goroutine throwaway statement inside the checkNode worker closure before passing it to SelectVictimsOnNode. This would isolate dry-run execution from the shared session state and prevent unintended mutations.
Code Pointers:
- Passing
stmtinDryRunPreemption: https://github.com/volcano-sh/volcano/blob/master/pkg/scheduler/actions/preempt/preempt.go#L623 - Calling
stmt.Evict(...)in candidate preparation: https://github.com/volcano-sh/volcano/blob/master/pkg/scheduler/actions/preempt/preempt.go#L539
heyy, are you working on it? or can i work?
Hi @vyagh , thanks for checking! I created this issue and have started working on it. I’ll share updates soon.