volcano icon indicating copy to clipboard operation
volcano copied to clipboard

Bug: Potential concurrent access to shared session statement `stmt` in `DryRunPreemption` → `SelectVictimsOnNode`

Open oindrilakha12-ui opened this issue 7 months ago • 2 comments

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

  1. Run the Volcano scheduler under a load that triggers scheduling preemption.
  2. In pkg/scheduler/actions/preempt/preempt.go, observe DryRunPreemption passing the live stmt into parallel workers managed by workqueue.ParallelizeUntil.
  3. Within the workers, SelectVictimsOnNode passes stmt into simulation paths and plugin callbacks.
  4. Tracing down, plugins invoke stmt.Evict(...) (or similar statement-modifying functions).
  5. Observe that multiple goroutines may access and modify the shared stmt object 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 stmt in DryRunPreemption: 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

oindrilakha12-ui avatar Apr 12 '26 11:04 oindrilakha12-ui

heyy, are you working on it? or can i work?

vyagh avatar Apr 12 '26 17:04 vyagh

Hi @vyagh , thanks for checking! I created this issue and have started working on it. I’ll share updates soon.

oindrilakha12-ui avatar Apr 14 '26 11:04 oindrilakha12-ui