Skip to content

core: recover from HTTP 416 when resuming a cached download - #1642

Merged
abiosoft merged 1 commit into
abiosoft:mainfrom
somaz94:fix/resume-complete-download
Sep 23, 2026
Merged

abiosoft merged 1 commit into
abiosoft:mainfrom
somaz94:fix/resume-complete-download

Conversation

@somaz94

@somaz94 somaz94 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #1575

Problem

When the cached .downloading file is already complete, for example because an earlier colima start was interrupted after the transfer finished but before the file was moved into place, every later colima start fails 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, and HTTPClient.Download returned it as an error while download.go kept the file for the next attempt. GitHub release assets answer this way, with Content-Range: bytes */<size>.

Fix

In the 416 branch the download is treated as complete when the size in Content-Range matches the existing file, so nothing is transferred and the SHA check in download.go still runs. For any other 416 on resume, such as a file larger than the remote or a 416 without Content-Range, nativeDownloader downloads the file again from the start once. The curl downloader is unchanged.

Testing

The new tests in util/downloader serve a file with http.ServeContent, which answers an unsatisfiable range with 416 and Content-Range: bytes */<size>. TestHTTPClient_Download_resume covers resuming a partial file, keeping a complete one and rejecting one larger than the remote, and TestNativeDownloader_Download_restartsRejectedResume checks the restart. Both fail on main with the error from the issue and pass with this change. go test ./... passes on macOS and in a golang:1.26.1 Linux container, and golangci-lint v2.11.3 (the CI version) reports no issues. I also checked with curl that GitHub's release asset host returns 416 with content-range: bytes */209768031 for 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.

Signed-off-by: somaz <genius5711@gmail.com>
somaz94 added a commit to somaz94/somaz94 that referenced this pull request Sep 23, 2026
@abiosoft
abiosoft merged commit bba803d into abiosoft:main Sep 23, 2026
17 checks passed
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.

Setting up a new VM fails in the Download

2 participants