Skip to content

[Code Quality] Propagate context.Context into syft image-scan loop (runSyftScans) #48555

Description

@github-actions

Description

pkg/cli/compile_pipeline.go checks ctx.Err() immediately before calling RunSyftOnLockFiles, but the context never actually reaches the scan loop. pkg/cli/syft.go:67 creates a fresh, standalone ctx := context.Background() inside runSyftScans, so the image-scan loop cannot be cancelled by Ctrl+C once started, even though the caller already holds a live signal-aware context.

Suggested Changes

  1. Change RunSyftOnLockFiles (in pkg/cli/compile_external_tools.go) to accept ctx context.Context as its first parameter.
  2. Thread that ctx through to runSyftScans in pkg/cli/syft.go.
  3. In runSyftScans, replace the internal ctx := context.Background() (line 67) with the passed-in ctx.
  4. Update call sites in pkg/cli/compile_pipeline.go to pass their local ctx instead of relying on the pre-check alone.
  5. Update any related tests / mocks for the new signature.

Files Affected

  • pkg/cli/syft.go (~line 67)
  • pkg/cli/compile_external_tools.go (RunSyftOnLockFiles)
  • pkg/cli/compile_pipeline.go (call sites)

Success Criteria

  • runSyftScans no longer calls context.Background() internally
  • The image-scan loop respects cancellation via the caller-provided context
  • make fmt and make test-unit pass

Source

Extracted from Repository Quality Improvement Report — context.Background() Call-Chain Leakage (discussion #48389), Task 4 (syft portion only — the logs_orchestrator_filters.go portion of this task was already fixed via #48479/#48470).

Priority

Medium - Improves cancellation correctness for long-running container image scans, but not blocking.

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent · sonnet50 · 43.6 AIC · ⌖ 7.19 AIC · ⊞ 9.8K ·

  • expires on Jul 28, 2026, 11:41 PM UTC-08:00

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions