Skip to content

fix: use oci.NewStorage for the ORAS_CACHE backing store - #2329

Merged
TerryHowe merged 1 commit into
oras-project:mainfrom
ogulcanaydogan:fix/oras-cache-process-safe-storage
Nov 10, 2026
Merged

TerryHowe merged 1 commit into
oras-project:mainfrom
ogulcanaydogan:fix/oras-cache-process-safe-storage

Conversation

@ogulcanaydogan

Copy link
Copy Markdown
Contributor

Fixes #2312

CachedTarget backed the ORAS_CACHE store with oci.New(), which maintains index.json and is not safe for concurrent writes from several processes. It now uses oci.NewStorage(), which has no index.json, as oras-go's content/cache does. The call site is the only change in cache.go: internal/cache takes a content.Storage, which oci.Storage satisfies, so nothing downstream relies on the tag or index behaviour of oci.Store.

Tests:

  • TestCache_CachedTarget now also checks that no index.json is created in the cache root.
  • TestCache_CachedTarget_sharedRoot runs 8 goroutines that each cache a different blob in the same root, and checks the content and that no index.json appears.

Both fail with oci.New() (index.json exists) and pass with this change, and go test -race ./cmd/oras/... and golangci-lint are clean. I can't reproduce the cross-process corruption deterministically, so the tests check that the file that makes it possible is no longer maintained. This is the first part of #2313, which would still move to content/cache

oci.New maintains index.json, which is not safe to share between concurrent processes, so two oras invocations using the same ORAS_CACHE could corrupt it. oci.NewStorage does not maintain index.json and is process-safe, as oras-go's own cache package uses it.

Signed-off-by: Ogulcan Aydogan <[email protected]>
@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.51%. Comparing base (917cfd9) to head (f1d339f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2329   +/-   ##
=======================================
  Coverage   73.51%   73.51%           
=======================================
  Files         157      157           
  Lines        6582     6582           
=======================================
  Hits         4839     4839           
  Misses       1454     1454           
  Partials      289      289           

☔ View full report in Codecov by Harness.
📢 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.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@TerryHowe
TerryHowe merged commit 02ffd9d into oras-project:main Nov 10, 2026
10 checks passed
@TerryHowe

Copy link
Copy Markdown
Member

Thanks!

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.

cleanup: use oci.NewStorage() for the ORAS_CACHE backing store

2 participants