Repository navigation
fix(update): resume an interrupted download - #28
Closed
xiaoyumuxi wants to merge 1 commit into
Closed
xiaoyumuxi wants to merge 1 commit into
xiaoyumuxi wants to merge 1 commit into
Conversation
Download and DownloadPatch wrote to a fresh temporary file and removed it on any failure, so a dropped connection threw away everything that had arrived and the next call started from byte zero. Nothing bounded a transfer that went silent either: the archive client has no total timeout, so a connection that stopped delivering held the call until the caller's context ended. Keep the bytes in a hidden file named by the feed's digest, and continue it with a Range request on the next call. A 206 is appended only when its Content-Range is exactly the bytes asked for; a 200 starts the file over, and a 206 for another part or a 416 asks once more for the whole file. The whole file is hashed again before it is kept, and a resumed file that fails the check is fetched once from scratch, so a partial a crash left behind cannot end up in the archive. A refusal still leaves no file behind. A transfer that stops part way now wraps the new ErrInterrupted: a failed connection, nothing arriving for a minute, 408, 429 or 5xx, or the end of ctx (wrapping its error too). An untrusted certificate and a redirect off HTTPS are not interruptions. A directory that already holds the verified file is returned without a request, and calls for the same file in one process take turns instead of writing the same partial.
Author
|
Superseded: upstream merged the same change as |
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.
Problem
Lithe's update download started from zero again after any interruption.
update.DownloadandDownloadPatchremoved the temporary file on every failure, including a dropped connection. Nothing ended a connection that went silent either: the archive client has no total timeout, so a connection that stopped sending held the download until the window was closed.Lithe also could not tell a cut-off patch download from a bad patch. Both made it fall back to the full archive, which is the larger download.
Change
.viva-update-<sha256>.partfile in the download directory. The next call sendsRange: bytes=N-for the rest.200starts the file over.206for another part, or a416, asks once more for the whole file.ErrInterrupted. It is returned for a failed connection, nothing arriving for a minute,408,429or5xx, or the end ofctx(the error wraps the context's error too).update/download_resume_test.go.The full description, the verification and the cost are in the upstream PR: vivaui#324.
Lithe's side, in the Lithe PR that moves the pin:
Branches
fix/update-download-resume: one commit,56a3522, branched from upstreammain10c5b92. It is the head of fix(update): resume an interrupted download vivaui/viva#324.lithe/update-download-resume-on-main(this PR): the same commit cherry-picked onto forkmain97fdbdd, as00d4569.mainintofix/update-download-resumeinstead would have put fork-only commits into the upstream PR.mainnext merges upstream, both copies make the same change.Tests
On this branch, macOS 27 / arm64:
gofmt -l .is clean.go vet ./...passes, and so doGOOS=windowsandGOOS=linuxgo vet ./update/ ./internal/... ./app/.go test ./... -count=1: 90 packages pass. The only failure iscmd/viva: its 14 packaging tests saythe program was built for macOS 13.0 or later but [mac] min_system says 12.0. They fail the same way on forkmain97fdbddwithout this change, because of the local toolchain.go test -race ./update/ -run TestDownload -count=20passes.desktop-go.sh test -race ./..., 58 packages pass. They ran through ago.workreplace whoseupdatesources are byte-identical to this branch; only the new416test was missing there.This PR needs merging before Lithe can use it: Lithe's updater now depends on
update.ErrInterrupted. Merging it, and moving Lithe'sdesktop/go.modpin to the merge result, are left to the maintainers.