Repository navigation
fix(segments): never run more connections than allowed when gaps remain - #637
Merged
Merged
Conversation
A batch ran one connection per incomplete segment. Resegmenting to fewer connections cannot join the gaps finished ranges leave, so after a 429 cut the connections to one, a download with three gaps still sent three requests at once: the server answered 429 again, which cancelled the two transfers it served after a few kilobytes, and every round left more, smaller segments. Against a server allowing two connections, a 64 MB download made 300 requests in 150 s and never finished, its segments growing past 600. The ledger now starts at most the batch's effective connections; the other lanes wait and go whole to the first connection free, before any split. The same download now finishes in 15 s with 11 requests.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Contributor
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
SegmentedDownloadHelperran one connection per incomplete segment.SegmentCalculator.resegmentcan't join the gaps that finished ranges leave between them, so it keeps at least one segment per gap (coerceAtLeast(merged.size)). A batch could therefore run more connections than its effective count.This is worst after a 429:
DownloadExecutionhalves the connections, down to one.I found this with a local server that allows two concurrent requests and answers 429 otherwise. A 64 MB download:
Fix
SegmentLedgernow starts at most the batch's effective connections (connections, fromeffectiveConnections(requestedAtStart)).SegmentLane.waiting). The first connection that frees up takes each one whole, before splitting any other lane.Same server and file after the fix: done in 15 s with 11 requests, SHA-256 matching, while another download was competing for the same two slots.
Tests
SegmentedDownloadHelperTest.downloadAll_moreGapsThanConnections_runsOnlyTheConnections:core,ftp,metalink,webdavandktorpass.