Repository navigation
One origin request budget, and a 429 that stops ending the session (#377) - #384
Merged
Merged
Conversation
…he session (#377) The reader classifies a 429 / 503 / 509 as metering rather than failure, then threw that away on the way up: the give-up arm returns a bare -1, FFmpeg renders it as "Operation not permitted", and the session's revive arm saw exactly what a genuinely dead source produces. It spent both of its two attempts inside a minute, each one reopening from byte 0 against an origin refusing precisely that, and ended on "source not readable in this session" while the same stream plays instantly on a fresh press of play. A metered read error now takes its own larger budget with a growing backoff (3s, 8s, 20s, 45s) instead of an immediate reopen, and surfaces PlaybackErrorKind.sourceRateLimited, so a host does not hand off to a second engine that the same origin will refuse. httpMaximumConnectionsPerHost is a per-URLSession cap and AVIOReader fetches over four pools, so against one signed CDN URL a pump range, a detour block and a probe could all be open at once, with the subtitle side reader sharing the same static pools. Those caps never composed. OriginRequestBudget counts requests per origin, which is what a metering origin counts, and unlike a connection cap it is equally true over HTTP/2, where a session multiplexes every request onto one connection. Counting is unconditional, capping is not: with no limit nothing waits, and a limit arrives from the host (LoadOptions.maxConcurrentSourceRequests) or from the origin itself, halving from the concurrency actually reached. At one slot the speculative paths switch off rather than queue, each falling back to the serial path it already had, which is what keeps this deadlock-free by construction. Measured against a metered origin serving one file, limit 1: budget learned from the refusals peak=2 429s=2 served=3, session survives maxConcurrentSourceRequests: 1 peak=1 429s=0 served=1 The tail prefetch was the request that got the pump refused: it goes out microseconds before the first data connection, so the origin saw two on the very first open, which is the "429 before any real number of requests" in the report. It is speculative, so it now takes a slot only if one is free. Two things a report could not say before: the negotiated transport is named once per origin from URLSessionTaskMetrics (h2 means a connection cap bounds nothing), and the slow-read summary carries origin=<n>inflight/<peak>peak. Reported by Rasmusmart57. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01E5UztmCZtNYPQpzdmSdmWG
…ugh to probably work Both concurrency tests set up "a waiter is parked" with a 300 ms sleep and then asserted against it. That is a margin against a derived time bound, and the CI macOS runner took it away: the same tests that pass locally in milliseconds sat behind a suite where individual cases were taking twenty seconds. The budget now reports how many callers are parked, so the tests wait for the state they mean to set up. They are deterministic and finish in 3-6 ms. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01E5UztmCZtNYPQpzdmSdmWG
Contributor
|
Thanks for the fast response on this! I've vendored the branch and I'm running with maxConcurrentSourceRequests: 1. Going to test this now and tomorrow, I'll report back! |
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: the reporter's retest is what closes #377.
The two defects
A 429 was read as a death.
AVIOReader.isRateLimitStatusexists and is used in seven places, all of them insideAVIOReader.swift.Sources/AetherEngine/Video/contains no reference to rate limiting at all. The classification dies at the give-up arm, which returns a bare-1; FFmpeg renders that as "Operation not permitted", andhandleVODReadErrorExitsees what a genuinely dead source produces. It spent both attempts ofreadErrorReviveGate(maxAttempts: 2)inside a minute, each one reopening from byte 0 against an origin refusing exactly that, then declared the source "not readable in this session". The reporter's own counter-evidence: backing out and pressing play works instantly.Four connection caps that never composed.
httpMaximumConnectionsPerHostis perURLSession, and the reader fetches overpersistentSession(2),chunkSession(2),probeSessiononURLSessionConfiguration.default(6) and a per-call streaming session, with the subtitle side reader sharing the same static pools. The reporter had this exactly right.They also identified the part that cannot be resolved from outside the engine: over HTTP/2 a URLSession multiplexes every request of a session onto one connection, so a connection cap bounds nothing while the origin still counts the requests. That makes their own patch (three sessions collapsed to one, cap 1) most likely a no-op.
URLSessionTaskMetrics.networkProtocolNamewas read nowhere in the tree; it now says which case an origin is, once per origin.What this does
OriginRequestBudget: counts requests per origin (keyed scheme+host+port, so a rotating signed token shares one ceiling). Counting is unconditional, capping is not. A limit arrives from the host (LoadOptions.maxConcurrentSourceRequests) or from the origin, halving from the concurrency actually reached on each refusal.PlaybackErrorKind.sourceRateLimited, so a dual-engine host does not hand off to a second player that meets the same refusal.Measured, not assumed
Against a connection-metered origin (limit 1, real Range support,
Scripts-free repro in the issue thread), playing one file:maxConcurrentSourceRequests: 1The tail prefetch was the request that got the pump refused: it leaves microseconds before the first data connection, so the origin saw two on the very first open. That is the "429 before any real number of requests" from the report, and it was invisible to the budget until it took a slot too.
aetherctl play --max-concurrent-requests Nis the reproduction knob.Tests
1883 pass. New:
OriginRequestBudgetTests(13, including FIFO fairness, the timeout race that would leak a slot permanently, and the redirect case above),RateLimitedSourceReviveTests(5), plus the slow-read line.