Repository navigation
fix(cli): give a freed provider permit to the lane that waited first - #2347
Merged
Merged
Conversation
bundle pull entries share each provider's --max-lane-streams permits, and every grant was a try_acquire race. A lane asks for an extra stream for a queued range once per growth pass, and at most once a second after a refusal. A sibling lane whose short legs restart, or whose leg ends trigger its own growth pass, asked the instant a permit freed and took every one: on testnet a bcl-only 1 GB range waited 450 s while a sibling entry opened 54 legs to bcl. A lane that `grow` refuses now claims the provider's next free permit. Each claim ahead of a lane holds back one free permit from it, and the kept permit for a sibling's first stream stays free after them, so the oldest claimant is served first. A grant or the lane's end clears the claim, and a claim not renewed for 3 x GROWTH_RETRY lapses. A lane's first lease (try_permit) still takes any free permit. decdn-client exports GROWTH_RETRY and documents on LaneWiden that a refused grow is asked again within it while the stream is still wanted. Closes #2341 Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The fairness mechanism is localized, internally consistent, and covered by targeted regression and lifecycle tests.
Review effort: Balanced
Findings: None
What changed in this PR
Adds FIFO provider-permit claims to prevent sibling lanes from starving queued bundle pull ranges.
Changes:
- Tracks expiring per-provider lane claims.
- Exports and documents the growth retry interval.
- Adds fairness, expiry, cleanup, and permit-release tests.
| File | Description |
|---|---|
crates/cli/src/commands/bundle_pull.rs |
Implements and tests FIFO permit claims. |
crates/cli/src/commands/cli_sources.rs |
Documents lane claim behavior. |
crates/client/src/scheduler.rs |
Exposes retry timing and documents its contract. |
crates/client/src/lib.rs |
Re-exports GROWTH_RETRY. |
crates/client/tests/snapshots/public_api__public_api.snap |
Updates the public API snapshot. |
CHANGELOG.md |
Records the starvation fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit 2d3b5cb in the Show a line coverage summary of the most impacted files.
Updated |
Review of the claim queue found a priority inversion: at a cap of 3 or more, a claim for an extra stream needs the kept permit free too, so it held off the restart of a lane that runs no stream while the one free permit could serve neither. The permit idled, and the bare lane stalled, until one of the claimant's own streams ended. A restart from a lane that holds no grant (its lease is already given back) now counts only the claims of other such lanes ahead of it, so every lane gets its first stream before any lane gets a second. The #2341 starver still queues: it restarted beside its extra streams. The claim logic moves onto ProviderStreams (take / forget), so grant holds one lock at a time and the queue arithmetic is tested directly: claims ahead, max-not-sum keep, renewal keeping place and taking the new keep, bare ordering, TTL, drop. Each of nine mutants of the arithmetic fails a test. A scheduler test pins that a refused grow is asked again every GROWTH_RETRY, which the claim TTL relies on. Docs note that a lane waiting out a node's extra-stream refusal is not asked, so its claim lapses. Refs #2341 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Summary
bundle pullentries share each provider's--max-lane-streamspermits, and every grant was atry_acquirerace. A lane asks for anExtrastream for a queued range once per growth pass, and at most once a second (GROWTH_RETRY) after a refusal. A sibling lane whose short legs restart (GrowFor::Restart, keep 0), or whose leg ends trigger its own growth pass, asked the instant a permit freed and so took every one. In the #2341 run,998030's bcl-only 1 GB range waited 450 s while7cbb48opened 54 legs to bcl.LaneStreamCap→ProviderStreams { semaphore, claims }). A lane thatgrowrefuses claims the provider's next free permit. Each claim ahead of a lane holds back one free permit from it, and the kept permit for a sibling's first stream stays free after them. A grant or the lane's end (Drop for ExtraPermits) clears the claim. A claim not renewed for3 × GROWTH_RETRYlapses, so a lane that stopped wanting the stream reserves nothing.ProviderStreams(take/forget).try_permit) still takes any free permit. Builds back off and hold nothing, and they run once per entry lane, not once per leg.decdn-clientexportsGROWTH_RETRYand documents onLaneWidenthat a refusedgrowis asked again within it while the stream is still wanted. The CLI's claim TTL relies on this. The public-api snapshot gains one line.The issue's other direction (a
Restarthonourskeepwhile another entry queues) does not fix the race. Both sides would then need two free permits, and the sibling still asks first.Cost: a permit that frees while a claim waits stays idle until the claimant's next ask (≤ 1 s). A lapsed claim reserves for ≤ 3 s.
Test plan
bundle_pulltests: bundle pull: a restarting lane worker wins every freed provider permit, so a sibling entry's queued range waits minutes #2341 repro, a stream-less lane going ahead, a dropped lane's claim clearing while others stay, plus directProviderStreams::taketests (claims ahead, max-not-sum keep, renewal keeps place and takes the new keep, bare ordering, own claim, TTL on a paused clock)growis asked again everyGROWTH_RETRY(fails if the retry doubles)cargo nextest run -p decdn-cli -p decdn-client: 1492 passedcargo clippy --workspace --all-targets --all-features -D warnings, rustdoc-D warnings, public-api snapshot, pre-commit--max-lane-streams 4. Expect noa queued range waits for a streamline beyond ~1–2 s for a single-provider rangeCloses #2341
🤖 Generated with Claude Code