Eliminate duplicate ContainerInspect calls in resume flow (closes #39458)

What does this MR do?

Eliminates 2 redundant ContainerInspect Docker API calls in the autoscaler prepareResume flow, reducing 4 calls to 2, and closes the TOCTOU window that existed between Prepare and Resume.

Background

In the autoscaler prepareResume flow:

  1. Prepare runs → calls resumeDependencies() → inspects build and helper containers
  2. Resume runs → inspects the same two containers again

This results in 4 ContainerInspect calls where 2 suffice, and introduces a TOCTOU window where container state could change between the two inspection rounds.

Solution

Move buildContainer and helperContainer from commandExecutor onto the embedded executor struct (next to buildContainerID), making them the single source of truth. resumeDependencies() populates them during Prepare via field promotion, so commandExecutor.Resume becomes a no-op — Prepare has already done the work.

Changes

File Change
executors/docker/docker.go Promote buildContainer / helperContainer fields to executor; populate them in resumeDependencies()
executors/docker/docker_command.go Remove duplicate fields from commandExecutor; make Resume a documented no-op
executors/docker/docker_test.go Remove now-redundant TestResume* tests; extend TestResumeDependencies to assert cached inspects are set
executors/docker/terminal_test.go Fix struct literal indentation after field promotion

Performance Impact

  • Before: 4 ContainerInspect calls per autoscaler resume
  • After: 2 ContainerInspect calls per autoscaler resume
  • Eliminates TOCTOU window between Prepare and Resume

Testing

  • Existing unit tests pass (go test ./executors/docker/...)
  • Manually verified resume flow with autoscaler enabled
  • No regressions in non-autoscaler Docker executor flows

Closes #39458 (closed)

Edited by Ashmit Sharma

Merge request reports

Loading