Repository navigation
fix: fail parallel download when a segment is not a partial response - #554
Open
jayhemnani9910 wants to merge 1 commit into
Open
jayhemnani9910 wants to merge 1 commit into
jayhemnani9910 wants to merge 1 commit into
Conversation
handleTask only checked the request error, so any status was merged into the file: a server without range support sent the whole file for every segment (a 3 MB file came out as 9 MB), an error page from one segment was spliced in, and a 404 page was saved as the file, all with Do() returning nil. Require 206 for each segment (200 is fine for a single segment) and an OK status on the HEAD request.
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.
ParallelDownloadwrites a wrong file and returnsnilwhen a segment request doesn't come back as a partial response. With a 3,000,000-byte file,SetConcurrency(3)andSetSegmentSize(1 << 20):http.FileServer(Range supported)python3 -m http.server(no Range support)err = nil, 9,000,000 bytes (the whole file once per segment)download segment 1048576-2097151: unexpected status 200 OK503err = nil, the error page spliced into the fileunexpected status 503 Service Unavailable404err = nil, the 404 page saved as the filebad status: 404 Not FoundhandleTaskonly checked the request error, which is nil for any HTTP status, so whatever body came back was merged into the output.Do()also accepted an error status on the HEAD request and used its Content-Length as the file size.Each segment now has to be
206 Partial Content. A200is accepted when there is only one segment, since the full body is then the right content.Do()returns an error when the HEAD request gets an error status.Added
parallel_download_test.gowithhttptestservers: one with Range support (file matches), one without (error, and a single-segment download still works), and a 404. It fails without the change.go test ./...passes, also with-racefor the new test. Also downloaded a 3 MB file frompython3 -m http.server: 9,000,000 bytes andnilbefore, an error after.