Skip to content

fix(retry): retry on connection reset by peer and unexpected EOF - #1567

Merged
TerryHowe merged 2 commits into
oras-project:mainfrom
idan-rahamim-lendbuzz:retry-connection-reset
Oct 13, 2026
Merged

TerryHowe merged 2 commits into
oras-project:mainfrom
idan-rahamim-lendbuzz:retry-connection-reset

Conversation

@idan-rahamim-lendbuzz

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

retry.DefaultPredicate now also retries a connection reset by peer (syscall.ECONNRESET) and an unexpected EOF (io.ErrUnexpectedEOF), next to the dial-timeout case. Go's net/http never retries a request that failed on a fresh connection, so without this a single reset from a registry (seen with AWS ECR) fails the whole operation even though the request would succeed a moment later and the retry policy is bounded.

Everything else is unchanged: ECONNREFUSED, a bare io.EOF and unrelated errors are still not retried, and Transport.RoundTrip keeps refusing to retry a body it cannot rewind.

Tests

  • policy_test.go: retry on a reset wrapped the way net/http returns it (*url.Error → *net.OpError → *os.SyscallError), retry on a wrapped io.ErrUnexpectedEOF, no retry on ECONNREFUSED and on an unrelated error.
  • client_test.go: Test_Client_RetryOnConnectionReset, an httptest server that hijacks the first connection, sets SetLinger(0) and closes it (RST), then serves 200; DefaultClient.Get gets the 200 on the second attempt. Skipped on Windows, where a reset surfaces as WSAECONNRESET, which errors.Is(…, syscall.ECONNRESET) does not match, so Windows keeps today's behaviour.
  • gofmt, go vet, go test -race ./registry/remote/... pass; the new lines are covered.

Notes for review

  • Retrying after a reset on a non-idempotent request is possible in theory; the predicate already retries 5xx/429/408 for any method, and the body-rewind rule in RoundTrip is unchanged, so this does not add a new class of behaviour. If a method-based narrowing is preferred, RoundTrip has the request and it is a small follow-up.
  • syscall.ECONNRESET compiles on linux, darwin, windows, js/wasm and wasip1; it is undefined on plan9, where the module already does not build.
  • Helm pins oras.land/oras-go/v2, so a backport to the v2 branch would be needed for it to benefit; I can open it once this is accepted.

Which issue(s) this PR fixes

Fixes #1566

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.

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

@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

@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 92.11%. Comparing base (2004497) to head (47c8f1c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1567      +/-   ##
==========================================
+ Coverage   92.08%   92.11%   +0.03%     
==========================================
  Files         103      103              
  Lines        8437     8439       +2     
==========================================
+ Hits         7769     7774       +5     
+ Misses        657      654       -3     
  Partials       11       11              

☔ 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 merged commit 055f8d1 into oras-project:main Oct 13, 2026
12 checks passed
TerryHowe pushed a commit that referenced this pull request Oct 13, 2026
…) (#1570)

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 #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]>
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.

retry: DefaultPredicate does not retry a connection reset on a fresh connection

2 participants