Skip to content

[Backport v2] fix(retry): retry on connection reset by peer and unexpected EOF - #1570

Merged
TerryHowe merged 1 commit into
oras-project:v2from
idan-rahamim-lendbuzz:backport-v2-retry-connection-reset
Oct 13, 2026
Merged

TerryHowe merged 1 commit into
oras-project:v2from
idan-rahamim-lendbuzz:backport-v2-retry-connection-reset

Conversation

@idan-rahamim-lendbuzz

Copy link
Copy Markdown
Contributor

Backport of #1567 to v2.

retry.DefaultPredicate retries 5xx, 429, 408 and dial timeouts, but returns a connection reset by peer (syscall.ECONNRESET) or an unexpected EOF (io.ErrUnexpectedEOF) as is. Go's net/http deliberately never retries a request that failed on a fresh connection, and the first request to a registry always is one, so a single reset (seen with AWS ECR) fails the whole operation although the policy is bounded and RoundTrip already rewinds request bodies. With this fix both are retried like a dial timeout; ECONNREFUSED, a bare io.EOF and unrelated errors are unchanged.

Helm pins oras.land/oras-go/v2, which is why this needs to be on v2.

Cherry-pick

policy.go is the merged change as is: the hunks apply cleanly, since v2's import block and DefaultPredicate are identical to main's before the fix. The tests could not be cherry-picked: on v2, policy_test.go has no Test_GenericPolicy_Retry* tables and client_test.go has no Test_Client_RetryAfterHonored, so the same coverage is added in this branch's layout: a table-driven Test_DefaultPredicate (reset and unexpected EOF retried; ECONNREFUSED and an unrelated error passed through) and Test_Client_RetryOnConnectionReset, identical to main's (an httptest server that resets the first connection with SetLinger(0) and serves 200 on the second attempt; skipped on Windows, where a reset surfaces as WSAECONNRESET). The commit message records the adaptation below the cherry picked from line.

Tests

On v2 without the fix, the new tests fail:

--- FAIL: Test_Client_RetryOnConnectionReset (0.00s)
    client_test.go:130: failed to do test request: Get "http://127.0.0.1:59258": read tcp 127.0.0.1:59259->127.0.0.1:59258: read: connection reset by peer
--- FAIL: Test_DefaultPredicate (0.00s)
    --- FAIL: Test_DefaultPredicate/connection_reset_by_peer_should_be_retried (0.00s)
        policy_test.go:150: expected error <nil>, got Get "https://registry.example/v2/repo/tags/list": read tcp: read: connection reset by peer
        policy_test.go:153: expected retry true, got false
    --- FAIL: Test_DefaultPredicate/unexpected_EOF_should_be_retried (0.00s)
        policy_test.go:150: expected error <nil>, got Get "https://registry.example/v2/repo/tags/list": unexpected EOF

With the fix, go test -race ./registry/remote/... passes, gofmt and go vet are clean on registry/remote/retry, and the new predicate lines are covered by Test_DefaultPredicate alone, so patch coverage holds where the client test is skipped. Test_Client_RetryOnConnectionReset passed 20/20 with -race.

Refs #1566

🤖 Generated with Claude Code

…s-project#1567)

net/http never retries a request that failed on a fresh connection, so a
single reset from a registry fails the whole operation although the retry
policy is bounded and RoundTrip already rewinds request bodies. Treat
syscall.ECONNRESET and io.ErrUnexpectedEOF as retryable in DefaultPredicate,
next to the dial timeout. ECONNREFUSED, a bare io.EOF and unrelated errors
are unchanged.

Backport of oras-project#1567 to v2; tests adapted to this branch's test layout.
(cherry picked from commit 055f8d1)

Signed-off-by: Idan Rahamim <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.09%. Comparing base (1a96f72) to head (8f151fb).

Additional details and impacted files
@@            Coverage Diff             @@
##               v2    #1570      +/-   ##
==========================================
+ Coverage   89.04%   89.09%   +0.04%     
==========================================
  Files          64       64              
  Lines        4948     4950       +2     
==========================================
+ Hits         4406     4410       +4     
+ Misses        533      531       -2     
  Partials        9        9              

☔ 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 merged commit 1788a6d into oras-project:v2 Oct 13, 2026
9 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.

2 participants