Repository navigation
fix(io): a redirect chain is one request budget, so a declared ceiling reaches the host that serves (#388) - #389
Merged
superuser404notfound merged 2 commits intoAug 17, 2026
Conversation
…g reaches the host that serves (#388) `LoadOptions.maxConcurrentSourceRequests` was registered for the origin of the URL the host loaded, and stopped there. On the shape it exists for (an Xtream portal that 302s to the media host that counts the provider's connections) that is the wrong host: the pump followed the redirect and streamed from the target while holding a slot booked against the portal, and the first backward read - MKV cues at the tail, a non-faststart moov, a backward scrub - opened a detour block against a target whose books showed nothing in flight. The panel saw two requests where the host had declared one, and the switch-off arrived only after the refusal that ceiling was meant to save. The host cannot route around it: it only knows the URL it loads, and resolving the redirect before load would spend the one connection the panel allows. So the budget folds an observed redirect into one chain, kept under the source's key. Every request keyed on either end is answered by the same server, which makes that the only reading that matches what the bytes do: the ceiling covers the chain, the pump's existing ticket is already the chain's (no re-keying a ticket mid-connection), and `requiresSerialRequests` is true at the pinned target from the first byte, so the detour falls back to the reposition path it already has. `peakInflight` becomes the chain's, so a later refusal halves from the concurrency the origin actually saw. Deliberate consequence, and the one place this departs from #377: a refusal now lowers the whole chain, portal included. That rule was kept per-host on the reasoning that the proxy did not refuse us, which is true and no longer the point - a request to the proxy for this source IS a request to the host that refused, because the proxy only ever answers it with a redirect there. A target that already belongs to a chain keeps it, so two portals on one edge host cannot spread a ceiling declared for one of them to the other. Reported by tschuegy from reading 6.28.0 and main @3777214e. The suggested fix was to inherit the host limit onto the pin and re-key the redirected pump's ticket; folding the chain is the same two effects with one mechanism, and it also closes what re-keying alone would have left (and briefly widened): requests still keyed on the source - a size probe, a second reader's pump - overlapping with requests keyed on the pinned target at the same server. Measured on the reporter's repro sketch, a loopback portal that 302s to a media origin that counts its own concurrency: before, a bounded 4 MB detour block landed at the media host at peak concurrency 2; after, no second request is issued and the backward read is served by repositioning. What a replacement connection overlaps with the connection it replaces (the #307/#380 teardown window) is unchanged and is not something the reader can promise away. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01E5UztmCZtNYPQpzdmSdmWG
…r the park CI's first run of it failed on a loaded runner with `parked` false and nothing granted, i.e. the background acquire had not happened at all: the observation window went to libdispatch, not to the budget. `cappedSerialises` already pays for this exact trap; this test now waits on the same two-stage signal, so a block that never got a thread reports that instead of a budget defect nobody measured. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01E5UztmCZtNYPQpzdmSdmWG
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.
Closes nothing yet: #388 stays open for the reporter's measurement against a real panel.
What was wrong
LoadOptions.maxConcurrentSourceRequestswas registered for the origin of the URL the host loaded (AetherEngine.swift,setHostLimit(_:for: url)) and stopped there. On the shape it exists for, an Xtream portal that 302s to the media host that counts the provider's connections, that is the wrong host:detourEligibletherefore readsrequiresSerialRequests(pinned) == falseand opens a detour block as a second request while the pump streams from the same server. On a one-slot panel that is the 509, and the halving that follows starts from a peak that never included the pump.What this does
Folds an observed redirect into one chain, kept under the source's key. Every request keyed on either end is answered by the same server, so:
requiresSerialRequests(pinned)is true from the first byte, so the detour falls back to the reposition path it already has;inflight/peakInflightdescribe the host the bytes actually come from.Linked at
redirectPreservingHeaders(every fetch path funnels through it, including hops no response ever pins) and again when a target is pinned.Deliberate departure from #377: a refusal now lowers the whole chain, portal included. That rule was per-host on the reasoning that the proxy did not refuse us, which is true and no longer the point, since a request to the proxy for this source IS a request to the host that refused. A target already on a chain keeps it, so two portals on one edge host cannot spread a ceiling declared for one of them to the other.
Measured
New
Issue388RedirectChainBudgetTests, including the reporter's repro sketch on loopback (a portal that 302s to a media origin that counts its own concurrency). Before: a bounded 4 MB detour block lands at the media host, peak concurrency 2. After: no second request is issued and the backward read is served by repositioning.ThrottledOriginServergrew a concurrency counter and an optionalrefuseAboveConcurrency, so a test can assert what the ORIGIN saw rather than what the reader believes it issued.Full suite: 1912 tests, 276 suites, green.
Not claimed: a replacement connection still briefly overlaps the one it replaces (the #307/#380 teardown window), so a peak of one at the server is not something the reader can promise. Not opening a second request on purpose while the pump streams is.
🤖 Generated with Claude Code
https://claude.ai/code/session_01E5UztmCZtNYPQpzdmSdmWG