Retry transient download errors - #3680
Merged
kichristensen merged 2 commits intoSep 3, 2026
Merged
Conversation
downloadFile only retried io.EOF/TLS-handshake-timeout, missing connection reset by peer (the actual CI failure) and any non-2xx status. Widen retry matching and also retry on 429/5xx. Applies to mixin/plugin feed+binary downloads and package listing search, which hit the same flaky-network class of bug. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AxEr3MmCK8sAP2EPfELnWs Signed-off-by: Kim Christensen <kimworking@gmail.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new retry paths can leak HTTP response bodies on error and don’t consistently drain/close bodies (and bind requests to context), which can cause resource issues and flaky behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR improves network resilience in Porter’s package management layer by adding shared retry helpers and applying them to mixin/plugin feed and binary downloads, addressing flaky CI failures caused by transient network issues.
Changes:
- Added shared retry classification helpers for transient network errors and transient HTTP statuses (429/5xx).
- Updated
downloadFileto retry on retryable network errors and transient HTTP statuses instead of failing immediately. - Updated
GetPackageListingsto retry on the same transient conditions and added tests covering retry behavior.
File summaries
| File | Description |
|---|---|
| pkg/pkgmgmt/search.go | Adds retry/backoff to package listing fetches and uses shared retry predicates. |
| pkg/pkgmgmt/search_test.go | Adds tests validating retry-on-503 and give-up behavior for listings. |
| pkg/pkgmgmt/retry.go | Introduces shared IsRetryableError / IsRetryableStatus helpers. |
| pkg/pkgmgmt/retry_test.go | Adds unit tests for the shared retry helpers. |
| pkg/pkgmgmt/client/install.go | Uses shared retry predicates and retries on transient HTTP statuses during downloads. |
| pkg/pkgmgmt/client/install_test.go | Adds tests validating retry-on-503 and give-up behavior for downloads. |
Review details
Suppressed comments (2)
pkg/pkgmgmt/search.go:75
- When retrying on a non-200 response, closing the body without draining it prevents HTTP connection reuse. Draining the body before closing helps avoid extra TCP handshakes during retries and in subsequent calls.
if resp.StatusCode != http.StatusOK {
statusCode := resp.StatusCode
resp.Body.Close()
resp = nil
pkg/pkgmgmt/client/install.go:222
- On non-200 responses that are retried, the body is closed without being drained, which prevents connection reuse and can add avoidable latency/handshakes during retries.
if resp.StatusCode != 200 {
statusCode := resp.StatusCode
statusErr := fmt.Errorf("bad status returned when downloading %s (%d) %s", url.String(), resp.StatusCode, resp.Status)
resp.Body.Close()
resp = nil
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Address Copilot review: close resp.Body on http.Client.Do error path, bind download request to ctx, drain body before close on non-2xx for connection reuse. Retry porter mixin install in CI bootstrap: freshly published canary assets can 404 briefly while still propagating on the CDN. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015NgAmqgoceW6u1d9XbUegF Signed-off-by: Kim Christensen <kimworking@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change
downloadFile(used for the mixin/plugin atom.xml feed and binarydownloads) already retried some transient errors, but its allowlist
only matched
io.EOF/io.ErrUnexpectedEOF/"TLS handshake timeout".It did not match "connection reset by peer", which is what actually
fails in CI, and any non-2xx status returned immediately with zero
retries.
pkg/pkgmgmt/retry.go:IsRetryableError(adds ECONNRESET,ECONNREFUSED, ETIMEDOUT, net.Error timeouts) and
IsRetryableStatus(429/5xx).
downloadFile(pkg/pkgmgmt/client/install.go) now uses these andretries on transient statuses instead of failing immediately.
GetPackageListings(pkg/pkgmgmt/search.go) gets the same treatmentfor consistency — same bare-
http.Get-no-retry bug, used bymixin search/plugin search.No new dependency; widened the existing hand-rolled retry loop instead
of adopting a retry library.
Follow-up commit, addressing Copilot review + a CI failure on this PR:
install.go/search.go: closeresp.BodywhenDo/Getreturns anon-nil response alongside an error, drain the body before closing on
non-2xx (connection reuse), and bind the download request to
ctxvia
NewRequestWithContext.magefile.go'sGetMixinsnow retriesporter mixin installup to3x with a 5s backoff. CI hit a 404 for
terraform-linux-amd64causedby a race with the terraform-mixin's own canary release publish (the
CDN asset's
last-modifiedmatched the failure timestamp exactly).Kept
IsRetryableStatusfail-fast on 404 (existing tests rely onthis for missing versions/typos); scoped the retry to the CI
bootstrap step where the race actually happens instead.
What issue does it fix
Closes #3678
Notes for the reviewer
preserving existing test expectations.
search.go'sGetPackageListingsfix is same bug class but notwhat Flaky CI: mixin download from cdn.porter.sh fails intermittently in integration test build #3678's CI failure actually hits — included for consistency,
happy to split out if preferred.
Checklist