Skip to content

fix(http): don't refetch the prefix when a retried takeover succeeds - #1607

Open
Grinv wants to merge 1 commit into
GopeedLab:mainfrom
Grinv:fix/resolve-takeover-refetch
Open

Grinv wants to merge 1 commit into
GopeedLab:mainfrom
Grinv:fix/resolve-takeover-refetch

Conversation

@Grinv

@Grinv Grinv commented Oct 24, 2026 •

Copy link
Copy Markdown

Related to #1600.

If a connection-limited server answers the first Range request with 429 or 503, connection 0 retries from the offset saved at Start while the Resolve prefetch keeps downloading. When a retry succeeds, commitResolveTakeover copies the prefetch and reads the overlap from the network again only to discard it.

Fix:

  • A retry in resolve-fallback mode starts at the current prefetch position. commitResolveTakeover now counts chunk progress from Chunk.Begin.
  • If the prefetch already reached the known size, connection 0 completes from it through completeFromResolveFallback and sends no request. With an unknown size this is skipped, because a prefetch stopped by Pause also ends without an error.

Traffic for a 4 MiB file in TestFetcher_RetriedTakeoverDoesNotRefetchPrefix (throttled server, 429 when busy):

Case main this PR
Resolve holds the only slot 2.00x 1.00x
Slot frees mid-prefetch 1.48x about 1.02x

This doesn't explain the three writers at 0, 25% and 50% in #1600. Zero-filled holes from servers that answer 403 to extra connections are #1592 (PR #1593).

go test -race ./internal/protocol/http/ and go test ./pkg/download/... pass, apart from the existing #1563 race reports fixed in #1606. Go 1.27.3, darwin/arm64, HTTP/1.1 only.

When the first Range request is refused with 429 or 503, connection 0
retried from the offset saved at Start while Resolve kept downloading.
The takeover then read the overlap from the network only to discard it,
so a server could send the file up to twice.

Retries in resolve-fallback mode now start at the current prefetch
position, and connection 0 completes from the prefetch when it already
holds the whole body.
@Grinv
Grinv requested a review from monkeyWie as a code owner October 24, 2026 07:09
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.

1 participant