Skip to content

feat(recipe): add context.Context to DataProvider interface for cancellable I/O #1109

Description

@mchmarny

Summary

The pkg/recipe.DataProvider interface methods (ReadFile, WalkDir) do not accept context.Context, so catalog and overlay file I/O cannot be cancelled or timed out by callers that hold a context. Adding context propagation through the interface and all implementations (EmbeddedDataProvider, LayeredDataProvider, MemoryDataProvider) would let validator and recipe-loader entry points honor their surrounding context deadline on the I/O path.

Motivation

coderabbitai flagged this on #1107:

Thread a timeout-bounded context into catalog load I/O. At Line 76, catalog file I/O is unbounded (dp.ReadFile(...)) and LoadWithDataProvider does not accept context.Context, so callers cannot enforce cancellation/timeout on this read path.

The concern is legitimate but the fix is out of scope for #1107 (a refactor preserving the pre-existing Load(version, commit) signature). The interface change ripples through:

  • pkg/recipe.DataProvider interface methods
  • EmbeddedDataProvider, LayeredDataProvider, MemoryDataProvider implementations
  • catalog.LoadWithDataProvider, catalog.Load shim
  • recipe.LoadFromFileWithProvider, recipe.LoadFromFile shim
  • Any external DataProvider implementers (Public (evolving) tier — see docs/integrator/public-api.md)

Impact today

Pre-existing — not a new regression from #1107. Risk: a hung NFS / sshfs read on --data directory under a slow network mount would block the validator goroutine until process termination, since the surrounding ValidatePhases(ctx) cancellation cannot interrupt the in-flight ReadFile.

Embedded reads cannot hang. Local-disk reads on a healthy filesystem are bounded by defaults.MaxExternalDataFileBytes + io.LimitReader. The exposure is narrow but real for network-backed --data mounts.

Acceptance

  • DataProvider.ReadFile/WalkDir accept context.Context as first parameter
  • All three in-tree implementations propagate context (Embedded is a no-op; Layered must check ctx.Err() between file opens; Memory same)
  • catalog.LoadWithDataProvider, recipe.LoadFromFileWithProvider, etc. take and propagate ctx
  • Validator entry points (ValidatePhases, ValidatePhase) pass their incoming ctx through to the catalog load
  • Back-compat shims (catalog.Load, recipe.LoadFromFile) bound context.Background() with a timeout from pkg/defaults
  • Test: a slow ReadFile returns context.Canceled when the caller cancels mid-read

Related

Metadata

Metadata

Assignees

Type

No type

Fields

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