Skip to content

Fix empty OCI layer extraction and add context cancellation#57

Merged
JAORMX merged 1 commit intomainfrom
fix/empty-layer-context-threading
Apr 4, 2026
Merged

Fix empty OCI layer extraction and add context cancellation#57
JAORMX merged 1 commit intomainfrom
fix/empty-layer-context-threading

Conversation

@JAORMX
Copy link
Copy Markdown
Contributor

@JAORMX JAORMX commented Apr 3, 2026

Summary

Fixes two chained bugs that caused VM startup to hang during OCI image extraction (#56):

  • Empty layers treated as errors: extractTar and extractTarSharedLimit returned an error when a tar archive had zero entries. Empty layers are legitimate OCI artifacts produced by ENV, LABEL, CMD, etc. — now treated as no-ops with a debug log.
  • No context cancellation in extraction: extractImage, extractImageLayered, extractTar, and extractTarSharedLimit did not accept context.Context, so slow/stalled operations (e.g. flat extraction fallback re-downloading layers) could hang indefinitely. All extraction functions now thread context and check ctx.Err() per tar entry. A contextReader wrapper enables cancellation during I/O reads. extractImageLayered uses errgroup.WithContext for proper propagation to concurrent goroutines.

Test plan

  • Updated TestExtractTar_EmptyArchive to expect success (was expecting error)
  • Added TestExtractTarSharedLimit_EmptyArchive — empty archive succeeds
  • Added TestExtractImageLayered_EmptyLayers — image with real + empty layer extracts correctly
  • Added TestExtractTar_ContextCancellation — cancelled context returns context.Canceled
  • Added TestExtractTarSharedLimit_ContextCancellation — same for shared-limit variant
  • All existing extraction tests updated to pass context.Background() and still pass
  • task fmt && task lint && task test-nocgo all green

Closes #56

🤖 Generated with Claude Code

Skip empty tar archives (0-entry layers from ENV/LABEL/CMD instructions)
instead of treating them as errors, which was causing layered extraction
to fail and fall back to flat extraction. Thread context.Context through
all extraction functions so slow or stalled operations can be cancelled.

Closes #56

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JAORMX JAORMX merged commit ce7d3b9 into main Apr 4, 2026
7 checks passed
@JAORMX JAORMX deleted the fix/empty-layer-context-threading branch April 4, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Layered extraction fails on empty OCI layers, flat fallback hangs indefinitely

1 participant