Repository navigation
fix(engine): continue on one connection when a range is ignored - #10
Conversation
troke12
left a comment
There was a problem hiding this comment.
This is the cleaner of #3/#10 and the tests are good. Requests:
- Silent corruption risk: the 200 path only checks
Content-Length == Total. If the file was replaced with one of the same size, this writes the new tail after the old prefix (onmainit errors). Please compare the 200's validator with the probe's — easiest after rebasing onto #2, and take the one-connection path only when the validator matches (or no If-Range was sent). - Reading the stored prefix via
discardPrefix(and the body read in #3) isn't covered by #1's idle timeout; route it through the timed read when rebasing. - The resume test's server returns 500 for any request starting at byte 0, which will break once #2's re-probe (
bytes=0-) lands.
Minor: when chunk 0 itself gets the 200, the full body is discarded and fetched again.
Note for the whole set (#1–#11): thanks a lot for these! They are all branched from 5350f79 independently, so every pair conflicts on CHANGELOG.md and most on download.go. main has also moved (e830f5d adds a stream downloader that touches download.go). Could you rebase onto current main and stack them in this order: #1 → #2 → #10 → #8 → #5/#6/#7/#11? #2, #3 and #10 each add their own pass loop / transferCancel in Start; one shared design would be much easier to merge.
troke12
left a comment
There was a problem hiding this comment.
This is the cleaner of #3/#10 and the tests are good. Requests:
- Silent corruption risk: the 200 path only checks
Content-Length == Total. If the file was replaced with one of the same size, this writes the new tail after the old prefix (onmainit errors). Please compare the 200's validator with the probe's — easiest after rebasing onto #2, and take the one-connection path only when the validator matches (or no If-Range was sent). - Reading the stored prefix via
discardPrefix(and the body read in #3) isn't covered by #1's idle timeout; route it through the timed read when rebasing. - The resume test's server returns 500 for any request starting at byte 0, which will break once #2's re-probe (
bytes=0-) lands.
Minor: when chunk 0 itself gets the 200, the full body is discarded and fetched again.
Note for the whole set (#1–#11): thanks a lot for these! They are all branched from 5350f79 independently, so every pair conflicts on CHANGELOG.md and most on download.go. main has also moved (e830f5d adds a stream downloader that touches download.go). Could you rebase onto current main and stack them in this order: #1 → #2 → #10 → #8 → #5/#6/#7/#11? #2, #3 and #10 each add their own pass loop / transferCancel in Start; one shared design would be much easier to merge.
A 200 for a smaller range is the whole file, so writing it at the range offset would corrupt the partial. Keep the contiguous prefix and fetch the remainder on one connection.
Review changes on top of the previous commit, which ports troke12#10 onto the pass loop If-Range (troke12#2) added, as one design: - The one-connection path for a whole-file 200 runs only when its validator matches the one sent as If-Range, or none was sent. A replaced file of the same size used to be joined to the old prefix; it now restarts (TestSubrangeOKWithOtherETagSameSizeRestarts). - A resume probe that finds ranges gone is no longer a changed file by itself: with the same validator the prefix is kept and the download continues on one connection, as when a transfer notices it. representationDiffers loses its range clause. - discardPrefix reads through the idle timer, so a stall while skipping the stored prefix is retried (TestDiscardPrefixStallRetries). - Tests: the ignored-range resume fixture answers the resume probe (bytes=0-); troke12#2's same-ETag subrange test now expects completion on one connection with the stored prefix kept. ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
45eeab5 to
237c080
Compare
|
Rebased onto current |
Review changes on top of the previous commit: - TestProbeFirstByteSingleChunk covers the regression the review found: a server answering 206 to bytes=0-0 but 200 to a range over the whole file, with one connection or a file too small to split. With troke12#10 on main the whole-file 200 is kept, so it completes in one request. - Test servers no longer tell the probe by its open-ended range, which bytes=0-0 broke (troke12#1, troke12#7 and troke12#10 fixtures): isProbe and probeRange in engine_test.go, and testRange reports the probe as not explicit. - The PR's test helper is renamed testWholeSpan (wholeFileRange is now a production function) and the test moves to probe_byte_test.go, as probe_test.go exists on main. ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
Review changes on top of the previous commit: - TestProbeFirstByteSingleChunk covers the regression the review found: a server answering 206 to bytes=0-0 but 200 to a range over the whole file, with one connection or a file too small to split. With #10 on main the whole-file 200 is kept, so it completes in one request. - Test servers no longer tell the probe by its open-ended range, which bytes=0-0 broke (#1, #7 and #10 fixtures): isProbe and probeRange in engine_test.go, and testRange reports the probe as not explicit. - The PR's test helper is renamed testWholeSpan (wholeFileRange is now a production function) and the test moves to probe_byte_test.go, as probe_test.go exists on main. ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
Review changes on top of the previous commit, which ports troke12#11 onto the pass loop on main: - The next connection opens once file bytes arrive on any connection after the last one opened, not once every opened connection has had bytes. A connection that never got its first byte froze the ramp for good, where main opened all N; now the others keep it going (TestRampPassesAStalledConnection). Without a timer, a server that refuses every transfer is still not asked on more connections. - ramp runs as its own goroutine holding a count on the pass's WaitGroup, and ends when every connection is open, the pass ends, or nothing is left to hand out (hasWork). A worker error no longer stops it: the run may still complete. - One-connection mode (troke12#10) and !RangeOK open a single connection. - Tests use no sleeps to show something did not happen: only file bytes open a connection, so while bytes are held back none can. They count opened connections (rampOpened), not requests, and tell the probe by bytes=0-0 (isProbe). ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
Review changes on top of the previous commit, which ports #11 onto the pass loop on main: - The next connection opens once file bytes arrive on any connection after the last one opened, not once every opened connection has had bytes. A connection that never got its first byte froze the ramp for good, where main opened all N; now the others keep it going (TestRampPassesAStalledConnection). Without a timer, a server that refuses every transfer is still not asked on more connections. - ramp runs as its own goroutine holding a count on the pass's WaitGroup, and ends when every connection is open, the pass ends, or nothing is left to hand out (hasWork). A worker error no longer stops it: the run may still complete. - One-connection mode (#10) and !RangeOK open a single connection. - Tests use no sleeps to show something did not happen: only file bytes open a connection, so while bytes are held back none can. They count opened connections (rampOpened), not requests, and tell the probe by bytes=0-0 (isProbe). ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
Summary
Some servers advertise ranges in the probe but answer a smaller range with
200and the whole file. Onmainthat chunk failed with "server ignored Range" after 8 retries. Now the bytes already stored are kept, the other connections stop, and the rest of the file is fetched on one connection: the stored prefix of the 200 body is skipped and the remainder is written at its offset. The download stays on one connection after a pause/resume (aloneis persisted).One design with If-Range (#2)
This runs in the pass loop #2 added. It does not add a second loop.
200to a ranged request:If-Range→ the file changed → restart (feat(engine): restart a download when the file on the server changes #2).If-Rangewas sent → the same file, so continue on one connection (this PR).Content-Lengththan the file is still an error.Commits
98f1863(Ryan Bagas): the original change, ported onto feat(engine): restart a download when the file on the server changes #2's pass loop (transferCancel, worker,fetch200 handling, state). The twoif_range_test/ignored_range_testcases fixed in the next commit fail at this commit.237c080: review changes. Validator check before the one-connection path, keep prefix on range loss at resume,discardPrefixthrough the idle timer, test fixes.Known limits
ETagand noLast-Modified, a replaced file of the same size cannot be detected. This is the reviewer's "no If-Range sent" case.Test plan
go test ./...andgo test -race ./internal/engineTestSubrangeOKWithOtherETagSameSizeRestarts: a same-size replacement with a new ETag restarts and gives the new file. Fails without the validator check.TestSubrangeOKWithSameETagContinuesAlone: the stored prefix is kept. The 200 body's first half differs, so the result shows it was skipped.TestIgnoredSubrangeKeepsFinishedBytes: resume against a server that ignores Range entirely; no transfer starts before the stored prefix. Fails if range loss discards the prefix.TestDiscardPrefixStallRetries: a stall while skipping the prefix is retried. Hangs (fails) with an untimed read.TestSubrangeOKFallsBackToOneConnection,TestPlanAloneKeepsContiguousPrefix,TestAloneSurvivesRestore,TestContiguousDoneStopsAtTheFirstHole✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)