Repository navigation
Conversation
A connection can take the tail of a chunk while another read is still in hand. Only the bytes that still belong to the chunk are written into its progress, so the same bytes are not counted twice.
troke12
left a comment
There was a problem hiding this comment.
Thanks, but I don't think this path is reachable. The only thing that moves ch.End mid-read is Split, which needs Remaining >= 2*MinChunkSize (128 KiB) and sets mid = Next() + Remaining/2, i.e. at least 64 KiB past the current position. The read buffer is exactly 64 KiB, so an in-flight buffer can't cross the new end. #6 keeps the same mid formula.
The test also doesn't hit the new check: the hook moves End before limit := ch.End is read, so the existing pre-write clamp already handles it, and a cut at 1024 isn't something Split can produce. It also adds a test hook (beforeWrite) to the production struct.
I'd rather not take it unless chunk/buffer sizes change. ownedSpan itself is clean.
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.
|
Closing per the review above: with the 64 KiB read buffer and |
Summary
Taking the tail of a chunk while that connection still has bytes in hand no longer counts those bytes twice. Progress stays within the file size.
Behavior
Test plan
go test ./...(61 tests)