Skip to content

fix(build-index): retry manifest downloads that fail with a network error - #759

Merged
thijmv merged 2 commits into
uber:masterfrom
PerryLink:fix/build-index-retry-network-errors-20261118
Nov 20, 2026
Merged

thijmv merged 2 commits into
uber:masterfrom
PerryLink:fix/build-index-retry-network-errors-20261118

Conversation

@PerryLink

Copy link
Copy Markdown
Contributor

Rebased on current master

This replaces #738, which was based on an older master. Two things changed since then:

The change and tests are unchanged apart from the conflict resolution. go build ./... and go 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
Poll builds the error returned to the resolver like this:

  • origin/blobclient/cluster_client.go:394 adds the origin address with %s,
    which stringifies the per-origin error and drops its type;
  • origin/blobclient/cluster_client.go:402 joins those strings with
    errutil.MultiError and formats them with %s again. MultiError has no
    Unwrap, so even a wrapped form would not be inspectable;
  • build-index/tagtype/docker_resolver.go:66 then asks
    httputil.IsNetworkError, which is a bare err.(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 and
build-index fails the tag resolution even though the failure was transient.

Fix

  • Wrap the per-origin error and the joined result with %w
    (cluster_client.go:394,402).
  • Give errutil.MultiError the Unwrap() []error method that errors.Is /
    errors.As understand since Go 1.20 (go.mod is go 1.24.0). The value
    receiver is deliberate: Join returns the MultiError value, and a pointer
    receiver would not be in the method set seen through the returned error.
  • Make httputil.IsNetworkError use errors.As instead of a type assertion.

The rendered error text is unchanged: %s and %w produce the same string, so
logs 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 Poll still lets callers find the
    httputil.NetworkError through errors.As and IsNetworkError.
  • TestDockerResolver_DownloadManifest_RetryOnWrappedNetworkError
    (build-index/tagtype/docker_resolver_test.go): a wrapped network error is
    retried MaxRetries + 1 times instead of being permanent. Old code made
    exactly one attempt (attempts: 1 in the failure log).
  • TestIsNetworkError (utils/httputil/httputil_test.go): bare, wrapped and
    negative cases.
  • TestMultiErrorUnwrap (utils/errutil/errutil_test.go): errors.Is reaches
    a sentinel inside a joined, wrapped MultiError.
go build ./...
go vet ./utils/httputil/ ./utils/errutil/ ./origin/blobclient/ ./origin/blobserver/ ./build-index/tagtype/
go test -race ./utils/httputil/ ./utils/errutil/ ./origin/blobclient/ ./origin/blobserver/ ./build-index/tagtype/

Known limitation

A connection that drops in the middle of the manifest body is still not retried
at this level. HTTPClient.DownloadBlob returns
fmt.Errorf("copy body: %s", err) (origin/blobclient/client.go:265), which is
not an httputil.NetworkError; only request-level failures are. Classifying the
body-copy error as a network error is a larger change and is left out of this
PR.

All seven call sites of IsNetworkError were checked: the other six receive
unbundled errors from httputil.Send / PollAccepted, so their behavior is
unchanged; only the docker resolver gains the retry.

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

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.

🟢 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 %w wrapping.
  • Enable error-chain inspection through MultiError.Unwrap and errors.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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Consider moving this test to blobclient/cluster_client_test.go.

Comment on lines +298 to +299
var networkErr httputil.NetworkError
require.True(errors.As(err, &networkErr))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Consider removing this assertion, as httputil.IsNetworkError already performs the same check.

Suggested change
var networkErr httputil.NetworkError
require.True(errors.As(err, &networkErr))

require.Less(time.Since(start), 80*time.Millisecond)
}

func TestIsNetworkError(t *testing.T) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.
@thijmv
thijmv merged commit 3c5f715 into uber:master Nov 20, 2026
12 checks passed
PerryLink added a commit to PerryLink/kraken that referenced this pull request Nov 21, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants