Skip to content

fix: bind media type detection to patch context#1587

Open
sozercan wants to merge 1 commit into
mainfrom
codex/fix-media-type-lookup-timeout-issue
Open

fix: bind media type detection to patch context#1587
sozercan wants to merge 1 commit into
mainfrom
codex/fix-media-type-lookup-timeout-issue

Conversation

@sozercan
Copy link
Copy Markdown
Member

@sozercan sozercan commented May 4, 2026

Motivation

  • Media type detection used context.Background() and remote lookups without a caller context, allowing Docker daemon or registry calls to hang indefinitely and bypass the patch timeout.
  • The patch flow called media type resolution before the BuildKit flow, so an unresponsive endpoint could cause a denial-of-service while the patch goroutine remained blocked.

Description

  • Introduces GetMediaTypeWithContext(ctx, imageRef, runtime) and keeps GetMediaType(...) as a backward-compatible wrapper that calls the new helper with context.Background().
  • Threads the caller ctx into local and remote resolution: localMediaType and podmanMediaType now accept a context.Context and use it for cli.ImageInspect and exec.CommandContext, and remoteMediaType passes the context to remote.Get via remote.WithContext(ctx).
  • Updates the patch decision path to call shouldExportAsOCI(ctx, ...), which uses GetMediaTypeWithContext so media type detection is bound to the patch timeout/cancellation.
  • Adjusts unit tests in pkg/utils/mediatype_test.go to use the new context-aware signatures.

Testing

  • Ran go test ./pkg/utils -run 'MediaType' and the media-type related unit tests passed.
  • Ran go test ./pkg/utils ./pkg/patch; some tests failed in this environment due to missing/blocked Docker/registry dependencies rather than the media-type change.
  • Attempted go test for a patch test (TestDoesNotExist) under a timeout; it timed out in this CI-like environment, indicating external integration dependencies rather than the fix itself.

Codex Task

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR binds container image media type detection to the patch operation’s caller context so local Docker/Podman inspection and remote registry lookups can be canceled or timed out (preventing hangs that bypass patch timeouts).

Changes:

  • Added utils.GetMediaTypeWithContext(ctx, ...) and threaded context.Context into Docker inspect, Podman CLI execution, and remote.Get.
  • Updated patch export decision logic to call a context-aware shouldExportAsOCI(ctx, ...).
  • Updated unit tests to use the new context-aware helper signatures.
Show a summary per file
File Description
pkg/utils/mediatype.go Introduces context-aware media type resolution and threads ctx into local/remote inspection paths.
pkg/utils/mediatype_test.go Updates unit tests to call the context-aware helper signatures.
pkg/patch/single.go Ensures OCI-vs-Docker export decision uses media type detection bound to the patch context.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread pkg/utils/mediatype.go
Comment on lines +33 to +34

func GetMediaTypeWithContext(ctx context.Context, imageRef, runtime string) (string, error) {
Comment on lines 168 to 173
func TestPodmanMediaType_ImageNotFound(t *testing.T) {
// This test covers the case where podman inspect fails because image doesn't exist
// Since podman is available in the test environment, we test with non-existent image

_, err := podmanMediaType("non-existent-image:test")
_, err := podmanMediaType(context.Background(), "non-existent-image:test")
require.Error(t, err)
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.18%. Comparing base (da17cae) to head (a07f5d4).
⚠️ Report is 36 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1587      +/-   ##
==========================================
+ Coverage   38.80%   41.18%   +2.37%     
==========================================
  Files          57       58       +1     
  Lines        9561    10114     +553     
==========================================
+ Hits         3710     4165     +455     
- Misses       5581     5653      +72     
- Partials      270      296      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

2 participants