core: recover from HTTP 416 when resuming a cached download - #1642
Merged
Merged
Conversation
Signed-off-by: somaz <genius5711@gmail.com>
somaz94
added a commit
to somaz94/somaz94
that referenced
this pull request
Sep 23, 2026
abiosoft
approved these changes
Sep 23, 2026
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.
Fixes #1575
Problem
When the cached
.downloadingfile is already complete, for example because an earliercolima startwas interrupted after the transfer finished but before the file was moved into place, every latercolima startfails with "resume failed for ... The server does not support the requested byte range" until the file is deleted by hand. #1348 reports the same symptom with the curl downloader.Cause
The native downloader resumes from the size of the leftover file by sending
Range: bytes=<size>-. When that size is already the full length, the server answers 416, andHTTPClient.Downloadreturned it as an error whiledownload.gokept the file for the next attempt. GitHub release assets answer this way, withContent-Range: bytes */<size>.Fix
In the 416 branch the download is treated as complete when the size in
Content-Rangematches the existing file, so nothing is transferred and the SHA check indownload.gostill runs. For any other 416 on resume, such as a file larger than the remote or a 416 withoutContent-Range,nativeDownloaderdownloads the file again from the start once. The curl downloader is unchanged.Testing
The new tests in
util/downloaderserve a file withhttp.ServeContent, which answers an unsatisfiable range with 416 andContent-Range: bytes */<size>.TestHTTPClient_Download_resumecovers resuming a partial file, keeping a complete one and rejecting one larger than the remote, andTestNativeDownloader_Download_restartsRejectedResumechecks the restart. Both fail on main with the error from the issue and pass with this change.go test ./...passes on macOS and in agolang:1.26.1Linux container, and golangci-lint v2.11.3 (the CI version) reports no issues. I also checked with curl that GitHub's release asset host returns416withcontent-range: bytes */209768031for a range that starts at the file size.AI disclosure: all of the code and tests in this PR were written with Claude Code (Claude Opus 5.5), and the checks above were run through it. I reviewed the whole diff before opening this PR.