Repository navigation
fix(build-index): retry manifest downloads that fail with a network error - #759
Conversation
…rror Poll stringified the per-origin error and the joined result, so the resolver never saw the NetworkError and turned a transient failure into a permanent one. Wrap both with %w, give errutil.MultiError an Unwrap() []error method, and make httputil.IsNetworkError use errors.As. The rendered error text is unchanged. Rebased on current master (keeps uber#737's httputil tests); replaces uber#738, whose integration jobs predated the Docker API version bump in uber#757.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change restoring request-level manifest-download retries.
No open issues 🎉
What changed in this PR
Restores build-index’s existing manifest-download retries for request-level network failures by preserving error types through the origin client and shared error utilities. Mid-body download failures remain out of scope.
Changes:
- Preserve per-origin and aggregate errors with
%wwrapping. - Enable error-chain inspection through
MultiError.Unwrapanderrors.As. - Add regression tests for error classification, propagation, and retry exhaustion.
| File | Description |
|---|---|
utils/httputil/httputil.go |
Recognizes wrapped network errors using errors.As. |
utils/httputil/httputil_test.go |
Tests bare, wrapped, nil, and non-network errors. |
utils/errutil/errutil.go |
Exposes aggregated errors through Unwrap. |
utils/errutil/errutil_test.go |
Tests sentinel lookup through wrapped aggregate errors. |
origin/blobserver/cluster_client_test.go |
Verifies network errors remain discoverable after polling origins. |
origin/blobclient/cluster_client.go |
Preserves underlying errors when reporting origin failures. |
build-index/tagtype/docker_resolver_test.go |
Verifies wrapped network failures receive the configured retries. |
Review effort: Balanced
| require.Equal(int64(256), bi.Size) | ||
| } | ||
|
|
||
| func TestPollWrappedErrorExposesOriginErrors(t *testing.T) { |
There was a problem hiding this comment.
nit: Consider moving this test to blobclient/cluster_client_test.go.
| var networkErr httputil.NetworkError | ||
| require.True(errors.As(err, &networkErr)) |
There was a problem hiding this comment.
nit: Consider removing this assertion, as httputil.IsNetworkError already performs the same check.
| var networkErr httputil.NetworkError | |
| require.True(errors.As(err, &networkErr)) |
| require.Less(time.Since(start), 80*time.Millisecond) | ||
| } | ||
|
|
||
| func TestIsNetworkError(t *testing.T) { |
There was a problem hiding this comment.
nit: Consider using a table test with giveErr err and wantNetworkErr bool.
Address the review nits: keep the Poll wrapped-error test next to the other blobclient tests, drop the errors.As assertion that IsNetworkError already covers, and make the IsNetworkError cases a table test.
Poll hands the same destination to every origin it tries, and DownloadBlob streams the response body into it. A failed attempt can leave a prefix of the blob behind, so retrying on another origin used to append the next origin's copy to partial data and corrupt manifest and layer downloads. Write through a restartableWriter that records how much the destination advanced. Before a retry, rewind a *bytes.Buffer, an io.Seeker or io.Discard and drop the bytes of the failed attempt; if the destination cannot be rewound and the attempt wrote something, stop the poll and return the original error. The first attempt is not rewound. localFileReadWriter gets Truncate so the store's Seeker-plus-Truncater destination can drop a partial write, and the download test is table-driven over every destination and failure path. Rebuilt on current master, so it keeps uber#759's wrapped Poll errors.
Rebased on current master
This replaces #738, which was based on an older master. Two things changed since then:
utils/httputil/httputil_test.go, so the old branch conflicts there; this branch keeps both fix(httputil): reset retry backoffs where they are built #737's tests andTestIsNetworkError;client version 1.24 is too old. Minimum supported API version is 1.40, which is unrelated to this change. This branch is based on current master, so the integration jobs run with the bump.The change and tests are unchanged apart from the conflict resolution.
go build ./...andgo test ./utils/httputil/ ./utils/errutil/ ./origin/blobclient/ ./origin/blobserver/ ./build-index/tagtype/pass locally.Problem
Since #502 the docker tag type retries a manifest download that fails with a
network error, but the network-error branch is dead code. On a failed attempt
Pollbuilds the error returned to the resolver like this:origin/blobclient/cluster_client.go:394adds the origin address with%s,which stringifies the per-origin error and drops its type;
origin/blobclient/cluster_client.go:402joins those strings witherrutil.MultiErrorand formats them with%sagain.MultiErrorhas noUnwrap, so even a wrapped form would not be inspectable;build-index/tagtype/docker_resolver.go:66then askshttputil.IsNetworkError, which is a bareerr.(NetworkError)assertion.The network error therefore reaches the resolver as a plain string error and is
turned into
backoff.Permanent: the manifest download is not retried andbuild-index fails the tag resolution even though the failure was transient.
Fix
%w(
cluster_client.go:394,402).errutil.MultiErrortheUnwrap() []errormethod thaterrors.Is/errors.Asunderstand since Go 1.20 (go.modisgo 1.24.0). The valuereceiver is deliberate:
Joinreturns theMultiErrorvalue, and a pointerreceiver would not be in the method set seen through the returned
error.httputil.IsNetworkErroruseerrors.Asinstead of a type assertion.The rendered error text is unchanged:
%sand%wproduce the same string, sologs and existing assertions are unaffected.
Tests
Four new tests. All four fail on the old code and pass with the fix:
TestPollWrappedErrorExposesOriginErrors(origin/blobserver/cluster_client_test.go):the error returned by
Pollstill lets callers find thehttputil.NetworkErrorthrougherrors.AsandIsNetworkError.TestDockerResolver_DownloadManifest_RetryOnWrappedNetworkError(
build-index/tagtype/docker_resolver_test.go): a wrapped network error isretried
MaxRetries + 1times instead of being permanent. Old code madeexactly one attempt (
attempts: 1in the failure log).TestIsNetworkError(utils/httputil/httputil_test.go): bare, wrapped andnegative cases.
TestMultiErrorUnwrap(utils/errutil/errutil_test.go):errors.Isreachesa sentinel inside a joined, wrapped
MultiError.Known limitation
A connection that drops in the middle of the manifest body is still not retried
at this level.
HTTPClient.DownloadBlobreturnsfmt.Errorf("copy body: %s", err)(origin/blobclient/client.go:265), which isnot an
httputil.NetworkError; only request-level failures are. Classifying thebody-copy error as a network error is a larger change and is left out of this
PR.
All seven call sites of
IsNetworkErrorwere checked: the other six receiveunbundled errors from
httputil.Send/PollAccepted, so their behavior isunchanged; only the docker resolver gains the retry.