Skip to content

pkg/cli: docker subprocess calls missing context (exec.Command → exec.CommandContext) #30507

@github-actions

Description

@github-actions

Problem

Two functions in pkg/cli/docker_images.go spawn Docker subprocesses using exec.Command without a context parameter, making them impossible to cancel or time-out from callers:

  • isDockerImageAvailableUnlocked (line 65): runs docker image inspect <image> with no cancellation
  • IsDockerAvailable (line 100): runs docker info with no cancellation

Neither function accepts a context.Context parameter, so if the Docker daemon hangs or is slow to respond, the call will block indefinitely regardless of any timeout or cancellation signal the caller holds.

Evidence

// pkg/cli/docker_images.go:65
cmd := exec.Command("docker", "image", "inspect", image)
err := cmd.Run()

// pkg/cli/docker_images.go:100
cmd := exec.Command("docker", "info")
err := cmd.Run()

Impact

  • Severity: Medium
  • Affected files: pkg/cli/docker_images.go
  • Risk: CLI commands that invoke these functions could hang indefinitely if Docker becomes unresponsive. Graceful shutdown is impossible for these paths.

Recommendation

Add context.Context parameters and use exec.CommandContext:

// Before
func IsDockerAvailable() bool {
    cmd := exec.Command("docker", "info")
    ...
}

// After  
func IsDockerAvailable(ctx context.Context) bool {
    cmd := exec.CommandContext(ctx, "docker", "info")
    ...
}

Update all callers to pass an appropriate context.

Validation

  • Update isDockerImageAvailableUnlocked and IsDockerAvailable to accept context.Context
  • Switch exec.Commandexec.CommandContext in both functions
  • Update all callers in pkg/cli/ to pass context
  • Run existing tests to verify no regressions

Estimated Effort: Small


Generated by Sergo — The Serena Go Expert | Run §25417004230

Generated by Sergo - Serena Go Expert · ● 439.7K ·

  • expires on May 13, 2026, 4:56 AM UTC

Metadata

Metadata

Labels

cookieIssue Monster Loves Cookies!sergo

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions