Skip to content

fix(proxycache): retry interrupted upstream blob fetches, verify digest before caching - #23601

Open
oscrx wants to merge 1 commit into
goharbor:mainfrom
oscrx:proxy-cache-retry-fix
Open

oscrx wants to merge 1 commit into
goharbor:mainfrom
oscrx:proxy-cache-retry-fix

Conversation

@oscrx

@oscrx oscrx commented Jul 22, 2026 •

Copy link
Copy Markdown

Comprehensive Summary of your change

The proxy cache fetches each upstream blob with a single GET. If that connection drops mid-stream, the pull fails and the blob is not cached (#23600).

What changes

  • Resume instead of fail. On a read error or early EOF, the fetch continues from the last byte received with a range request. At most 3 resumes with 1s/2s/4s backoff. It gives up on a 429 and stops when the pulling client disconnects. This applies to the client-facing fetch and both background cache fetches.
  • PullBlobChunk checks what it got back. It now rejects a 200 for a partial range and a 206 whose Content-Range starts at a different offset, because splicing either in would corrupt the blob. This function is shared with chunked replication, and it is the only change outside the proxy package.
  • Digest check before caching. The background cache fetches hash the stream as it passes, in constant memory, and fail the push on a mismatch.

A pull that succeeds first time makes no extra upstream requests. No config, API or docs change.

Where to look

About 280 of the 780 added lines are code; the rest is tests and a regenerated mock. The logic is in src/controller/proxy/blobretry.go, and the PullBlobChunk check is in src/pkg/registry/client.go.

Issue being fixed

Fixes #23600

Please indicate you've done the following:

  • Well Written Title and Summary of the PR
  • Label the PR as needed. "release-note/ignore-for-release, release-note/new-feature, release-note/update, release-note/enhancement, release-note/community, release-note/breaking-change, release-note/docs, release-note/infra, release-note/deprecation"
  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Made sure tests are passing and test coverage is added if needed.
  • Considered the docs impact — no config/API surface changed, so no docs update is needed.

Copilot AI review requested due to automatic review settings July 22, 2026 08:53
@oscrx
oscrx requested a review from a team as a code owner July 22, 2026 08:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds resumable proxy-cache blob fetching and digest verification before local caching.

Changes:

  • Adds bounded retries using HTTP range requests.
  • Verifies cached blob digests.
  • Adds retry and corruption tests.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/controller/proxy/blobretry.go Implements retry and verification readers.
src/controller/proxy/blobretry_test.go Tests reader behavior.
src/controller/proxy/controller.go Integrates retries and verification.
src/controller/proxy/controller_test.go Tests controller cache population.
src/controller/proxy/manifestcache.go Protects manifest dependency caching.
src/controller/proxy/manifestcache_test.go Tests dependency blob handling.
src/controller/proxy/remote.go Adds ranged blob reads.
src/testing/controller/proxy/remote_interface.go Extends the remote mock.
Files not reviewed (1)
  • src/testing/controller/proxy/remote_interface.go: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/controller/proxy/remote.go Resolved
Comment thread src/controller/proxy/blobretry.go Resolved
Comment thread src/controller/proxy/blobretry.go Resolved
Copilot AI review requested due to automatic review settings July 22, 2026 09:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • src/testing/controller/proxy/remote_interface.go: Generated file

Comment thread src/pkg/registry/client.go Resolved
Comment thread src/controller/proxy/blobretry.go Resolved
Copilot AI review requested due to automatic review settings July 22, 2026 09:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • src/testing/controller/proxy/remote_interface.go: Generated file

Comment thread src/controller/proxy/blobretry_test.go Resolved
@oscrx
oscrx force-pushed the proxy-cache-retry-fix branch from c177a8d to 2a476c7 Compare July 22, 2026 09:31
Copilot AI review requested due to automatic review settings July 22, 2026 09:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • src/testing/controller/proxy/remote_interface.go: Generated file

Comment thread src/controller/proxy/blobretry.go Resolved
Copilot AI review requested due to automatic review settings July 22, 2026 09:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • src/testing/controller/proxy/remote_interface.go: Generated file

@Vad1mo

Vad1mo commented Jul 23, 2026

Copy link
Copy Markdown
Member

What negative effect might a retry have on rate limits?
If a negative effect is possible, I would suggest to wrap this feature behind a feature flag.

@codecov

codecov Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.09901% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.29%. Comparing base (e7dbdea) to head (6e372e3).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/controller/proxy/blobretry.go 93.15% 5 Missing ⚠️
src/pkg/registry/client.go 83.33% 3 Missing ⚠️
src/controller/proxy/controller.go 33.33% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #23601      +/-   ##
==========================================
+ Coverage   74.24%   74.29%   +0.05%     
==========================================
  Files        1096     1097       +1     
  Lines      103602   103701      +99     
  Branches     3079     3079              
==========================================
+ Hits        76918    77046     +128     
+ Misses      26314    26287      -27     
+ Partials      370      368       -2     
Flag Coverage Δ
unittests 74.29% <90.09%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/controller/proxy/manifestcache.go 62.29% <100.00%> (+4.91%) ⬆️
src/controller/proxy/remote.go 15.00% <100.00%> (+15.00%) ⬆️
src/controller/proxy/controller.go 28.47% <33.33%> (+3.82%) ⬆️
src/pkg/registry/client.go 73.27% <83.33%> (+2.99%) ⬆️
src/controller/proxy/blobretry.go 93.15% <93.15%> (ø)

... and 7 files with indirect coverage changes

🚀 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • src/testing/controller/proxy/remote_interface.go: Generated file

Copilot AI review requested due to automatic review settings July 23, 2026 11:54
@oscrx

oscrx commented Jul 23, 2026

Copy link
Copy Markdown
Author

Good question. Two things worth separating here:

How much extra load can retry actually add? It only ever triggers on a genuinely interrupted connection (dropped/reset mid-transfer), never on a normal successful pull, and it's bounded to at most 3 extra attempts per interrupted blob with exponential backoff (1s/2s/4s) - not a multiplier on regular traffic. I'd actually argue this reduces aggregate upstream load in the failure case: today, an interrupted blob fails the whole pull outright, so the kubelet/docker client has to retry the entire image (manifest + every blob) from scratch. This resumes just the missing tail of the one interrupted blob via a Range request instead, which is strictly less upstream traffic than an outer full-image retry.

Where you're right that there was a real gap: if a resume attempt itself got rate-limited (429), the code was treating that the same as any other transient error and retrying it with the same 1-4s backoff - which won't help against a real rate limit (those typically need a much longer cool-down) and just adds more rejected requests. Fixed that in bbc3c78: a rate-limited resume now gives up immediately instead of consuming the rest of the retry budget, using the existing errors.IsRateLimitError check (same one already used elsewhere in this file for manifest 429 handling).

Given the above I'd rather not add a feature flag - the behavior is already bounded and opt-out-shaped (only fires on failure), and a flag adds real config/test surface for a fairly narrow edge case. Happy to reconsider if you still think it's warranted, though.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • src/testing/controller/proxy/remote_interface.go: Generated file
Comments suppressed due to low confidence (1)

src/pkg/registry/client.go:414

  • Validate the complete Content-Range, not only its start. PullBlobChunk is also used by copyBlobByChunk (src/controller/replication/transfer/image/transfer.go:429-440), so a server can currently answer a request for bytes=0-4 with 206 Content-Range: bytes 0-10/11; this check accepts the full body even though it violates that caller's chunk contract. Parse and require the returned end to equal end (and, when blobSize is known, the total to equal it), with a regression test for a matching start but mismatched end.
		cr := resp.Header.Get("Content-Range")
		got, crErr := parseContentRangeStart(cr)
		if crErr != nil || got != start {
			defer resp.Body.Close()
			return 0, nil, fmt.Errorf("registry returned Content-Range %q for requested range bytes=%d-%d, refusing to treat it as that chunk", cr, start, end)

@oscrx
oscrx force-pushed the proxy-cache-retry-fix branch from bbc3c78 to 586ab1f Compare July 28, 2026 21:51
@oscrx

oscrx commented Jul 28, 2026

Copy link
Copy Markdown
Author

All the comments in the code and the commit messages are very verbose, I can condense a lot of that after initial review I think

@github-actions

Copy link
Copy Markdown

This PR is being marked stale due to a period of inactivty. If this PR is still relevant, please comment or remove the stale label. Otherwise, this PR will close in 30 days.

@github-actions github-actions Bot added the Stale label Sep 27, 2026
@oscrx

oscrx commented Oct 1, 2026

Copy link
Copy Markdown
Author

Not stale

@snake1glide

snake1glide commented Nov 9, 2026 •

Copy link
Copy Markdown

can you merge it faster, please, it hurts T_T

@oscrx

oscrx commented Nov 10, 2026

Copy link
Copy Markdown
Author

I'll rebase so it's mergable again. I would love a review.

@oscrx
oscrx force-pushed the proxy-cache-retry-fix branch 3 times, most recently from be2ae06 to 47b0e65 Compare November 14, 2026 17:00
Comment thread src/controller/proxy/blobretry.go Outdated
// cache: interrupted reads are resumed, and the content is verified against
// desc.Digest so a corrupted blob fails the push instead of being committed.
// The copy is detached from any pulling client, hence its own context.
func openCacheBlobReader(r RemoteInterface, remoteRepo string, desc distribution.Descriptor) (io.ReadCloser, error) {

@stonezdj stonezdj Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggest to use openVerifiedBlobReader as the function name, because it is read and verify.

@stonezdj
stonezdj force-pushed the proxy-cache-retry-fix branch from 47b0e65 to 6e372e3 Compare November 23, 2026 08:56
…st before caching

The proxy cache fetched every blob with a single GET and no retry, so a
connection dropped mid-stream failed the pull and left the blob uncached.

Wrap the upstream body in a reader that, on a mid-stream read error or a
premature EOF, resumes from the last byte read with a range request
(RemoteInterface.BlobReaderAt, backed by the existing PullBlobChunk). It
resumes at most 3 times with exponential backoff, gives up on a 429, and
stops once the caller's context is canceled or the reader is closed. The
client-facing fetch and both cache-populate fetches use it.

PullBlobChunk now rejects a response that isn't the requested range - a
200 for a partial range, or a 206 whose Content-Range starts elsewhere -
because splicing it in at the requested offset would corrupt the blob.

The cache-populate fetches also verify the content against the blob
digest, so a corrupted body fails the push to local storage.

Fixes goharbor#23600

Signed-off-by: Oscar Wieman <oscar@oscarr.nl>
@oscrx
oscrx force-pushed the proxy-cache-retry-fix branch from 6e372e3 to 94df648 Compare November 23, 2026 11:48

This branch has not been deployed

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

Labels

release-note/update Update or Fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proxy cache: no retry on interrupted upstream blob fetch, and no digest verification before caching

8 participants