Skip to content

A stale pinned redirect target answers 509 forever after a pause-resume; the keep-pin rule has no bound, the streak resets on window-served reads, and the faulted-refill pacing is erased by its own reconnect #380

Closed

Description

@tschuegy

What happened?

Paused a VOD series episode for a few minutes on the couch, pressed play again. Playback resumed
for a few seconds (the resident read-ahead), then picture and sound froze for ~60 s, then the
session healed by itself. No user action in between.

The log tells a clean story: after the resume, every reconnect of the persistent reader against
the pinned post-redirect URL was answered 509, for 20 generations across ~85 s (gen
8→20, plus the ladder restarts in between). The fresh demuxer the segment layer eventually built
— whose brand-new reader resolves through the source URL and follows a fresh 302 — got its
first data after 452 ms from the same host. The origin was never down; the pinned target's
session was dead.

This is the other 509 shape, the one the #307 follow-up's keep-pin rule (8a8e00b0, 6.15.2)
wasn't written for. That rule models the lingering slot: the connection being replaced still
occupies the panel's only slot, it frees in seconds, the pin is fine, re-resolving wastes the one
request there is no room for. All still true — for seconds. Here the reader had held no
connection at all for minutes
(the #310 high-water end: a paused player holds no flow), the
edge host reaped the session server-side, and after that the pinned URL can only ever answer 509.
Only a fresh redirect heals it, and the keep-pin rule has no bound, so the reader never asks for
one.

Two smaller mechanisms turn that policy gap into the full 60 s freeze:

  1. The streaks reset on window-served reads, not on network progress. The window-serve branch
    of readPersistent does unproductiveReconnects = 0; rateLimitStreak = 0 on every served
    read (AVIOReader.swift:1406-1407 @ 73354ec8) — in the same loop iteration that then makes
    the faulted-refill decision. So while the runway drained, every replacement attempt was
    charged streak=1 (the log shows replacing a faulted connection … (streak=1 status=509)
    three times with 4100 KB → 1028 KB → 0 KB of read-ahead left), the bounded give-up was
    unreachable, and after the empty-window ladder finally exhausted at 7, one served byte reset
    the whole ladder and it started over (… exhausted … (7 consecutive), then (8 consecutive),
    then a fresh streak=1).

  2. The faulted-refill pacing is erased by the reconnect it authorises.
    chargeFaultedRunwayRefill sets nextFaultedRefillAt = now + delay
    (AVIOReader.swift:1682), then the caller runs startPersistentConnection, which resets it
    to .distantPast (AVIOReader.swift:2057). The announced "next attempt in 1.0s" is never
    honoured — attempts run on read cadence against the origin that is refusing them.

Because the reader neither fails the read while the window can serve (by design) nor ever
re-resolves, the session only heals once the segment layer runs its full escalation: the 30 s
forward-wait, the march-dead second GET, the 5 s stopWait, a fresh demuxer. That is the ~60 s the
viewer sits through.

Steps to reproduce

Needs an Xtream-style origin whose stream URL 302s to an edge/load-balancer host that expires
idle sessions (mine: aggregator → panel → 302 → edge, max_connections=1).

  1. engine.load() a progressive-MP4 VOD through such an origin; play a couple of minutes.
  2. Pause. The reader ends its connection at high water (Long-suspended data tasks holding full receive windows starve every Network.framework flow in the app process on tvOS — close-and-rerequest at high water would avoid the dormant state (field dose-response inside) #310) — no flow held, correct.
  3. Wait 3–5 minutes; the edge reaps the session server-side.
  4. Resume. The low-water refill reconnects to the pinned edge URL → 509 → the storm above:
    playback runs a few seconds off the window, then freezes ~60 s until the Loopback-HLS: the final segment of a long 4K DV title never completes at EOM — AVPlayer parks ~0.1s from the end (WaitingToMinimizeStalls) → -12889; resuming into the tail can't start a master #169 restart path
    rebuilds a demuxer whose reader resolves through the source.

AetherEngine version or commit SHA

6.26.0

Host app

Custom / my own integration

Platform

tvOS

OS version

tvOS 26.6

Device / chip

Apple TV 4K (3rd gen)

Playback path

Native AVPlayer

Source media (for playback bugs)

MP4 via HTTP progressive, h264 1920x960, 2× AAC audio, 8× ASS subtitle streams, 915 MB,
duration 2485 s. Served by an Xtream-style panel: HTTPS front → 302 → plain-HTTP edge host,
max_connections=1, no suffix-range support.

Error codes / log lines

[AVIOReader] pump replacing a faulted connection at offset 72017621 with 4100KB of read-ahead left (streak=1 status=509, next attempt in 1.0s)
[AVIOReader] pump conn start gen=8 offset=72017621 len=32MB
[AVIOReader] pump gen=8 rejected response status=509 at offset 72017621
[AVIOReader] pump conn gen=8 ended with error: Abgebrochen
[AVIOReader] pump replacing a faulted connection at offset 72017621 with 1028KB of read-ahead left (streak=1 status=509, next attempt in 1.0s)
[AVIOReader] pump replacing a faulted connection at offset 72017621 with 0KB of read-ahead left (streak=1 status=509, next attempt in 1.0s)
[AVIOReader] pump conn ended at offset 72017621 status=509, reconnecting (streak=2 retryAfter=0.0s)
   … streak=3,4,5,6 with real backoff …
[AVIOReader] pump reconnect exhausted at offset 72017621 status=509 (7 consecutive rate-limited)
[AVIOReader] slow read: 44581ms at offset=72013317 detour=0(0ms,0fetch) stallWaits=6(304ms,6signaled) tailWaits=0(0ms) reconnects=6 backoff=44272ms lockWait=0ms connect=3ms staleGenDropped=0b iters=13 unaccounted=1ms gen=9->15
[AVIOReader] pump reconnect exhausted at offset 72017621 status=509 (8 consecutive rate-limited)
[AVIOReader] pump replacing a faulted connection at offset 72017621 with 0KB of read-ahead left (streak=1 status=509, next attempt in 1.0s)
   … gen=16..20 all 509 …
[HLSVideoEngine] seg30: cache miss after 30001ms (cache=25 restarted=false)
[HLSVideoEngine] seg30: #169 forward-wait march dead (front=29 frozen across a full wait); escalating to restart
[HLSVideoEngine] restart at idx=30: old producer wedged in a read past 5s; aborted it and reopened a fresh demuxer
[AVIOReader] pump conn start gen=1 offset=0 len=8MB
[AVIOReader] File size: 915393993 bytes (data connection)
[AVIOReader] Cached resolved URL host=<edge>
[AVIOReader] pump gen=1 first data after 452ms

Anything else

The retryAfter is always 0.0s — this panel sends no Retry-After on its 509s.

I have a fix ready and will open a PR right after this: the rate-limit keep-pin gets a bounded
grace (3 paced attempts, then the pin is dropped for exactly one re-resolve; a 200/206 re-pins),
the streaks reset only when the current generation has delivered data, and the faulted-refill
timestamp survives startPersistentConnection (released by first data or a seek). The two-attempt
lingering-slot tests in ResolvedURLInvalidationTests stay green — that shape keeps its grace —
and the permanent-509 case keeps the same bounded give-up, now with the re-resolve spent inside
the same seven attempts. Verified against a two-server loopback rig (source mints per-request
lease URLs, CDN 509s dead leases forever): the unfixed reader burns 20 boundary attempts and
fails the read; the fixed one heals in 4 attempts with exactly one source resolve.

Activity

  1. added 2 commits that reference this issue on Aug 17, 2026
  2. superuser404notfound commented on Aug 17, 2026

    @superuser404notfound
    Owner

    Fixed on main: #381 merged as d35d078, plus a follow-up in 02416c2. Not released yet. Leaving this open for the retest.

    Two things this report earned beyond its own fix.

    An independent second origin, filed the same week

    #377 is a different reporter, a different provider, 429 rather than 509, and mid-playback rather than post-resume. Their retest trace:

    [AVIOReader] slow read: 32513ms at offset=0 ... reconnects=6 backoff=31968ms ... refusals=9
    [AVIOReader] pump conn start gen=8 offset=0 len=32MB
    [AVIOReader] Cached resolved URL host=nexus-175.neur.tb-cdn.st
    [AVIOReader] pump gen=8 first data after 210ms
    

    45 s of refusals against the pin, then 210 ms once a fresh demuxer's reader re-resolved. Your 452 ms, on someone else's CDN. Their pinned host also changes between sessions, so those are per-session signed targets with their own expiry, which is the shape your grace bound is written for. They had reached the same conclusion from the other end: a refusal that arrives with a single request in flight is not a meter counting anything, it is a lease that has died.

    The streak reset had two more branches

    Your diagnosis was right about the mechanism and one branch short of its extent. The read loop serves from memory in three places and all three cleared the streaks:

    The span branch is the one that reaches a metered origin. A refusal hands the origin to the request budget added in 6.28.0, which caps it to one request and takes the detour out of service, while the spans keep serving. So "one served byte reset the whole ladder and it started over" was still reachable through the branch that runs first. That is 02416c2, together with dropping the #if DEBUG from both pin lines: with your bounded grace the drop is a decision the ladder makes rather than a reaction to an expiry status, and a rung only the field can trigger is worth nothing if the field cannot see it.

    The two lines worth pulling from a retest are now release-visible and adjacent:

    [AVIOReader] Dropped resolved URL cache (rate-limited x3 through pinned URL)
    [AVIOReader] Cached resolved URL host=<fresh target>
    

    followed by a fast first data. If instead the fresh target answers 509 identically, the pin was never the problem on your panel and that would be worth knowing.

  3. superuser404notfound commented on Aug 17, 2026

    @superuser404notfound
    Owner

    Released in 6.29.0. Thank you for the report and the PR.

    That release also carries the follow-up: the other two places where a read served without touching the network reset the reconnect ladders (the retained head/tail spans, and the detour cache's resident-block hit, which could not tell a block it fetched from one it already had). The head/tail branch is the one that reaches the field shape described here, since unlike the detour it is not taken out of service on a metered origin.

  4. tschuegy commented on Aug 17, 2026

    @tschuegy
    ContributorAuthor

    Retested on 6.30.0, Apple TV 4K, tvOS 26.6, against the reported origin. The bounded grace fired, the reader healed itself, and the player never saw it.

    Shape: a series .mkv (1.82 GB, 2802 s) through the redirecting portal, native AVF route (remux → HLSLocalServer → AVPlayer). maxConcurrentSourceRequests = 1, so the pump also reports tail prefetch skipped: this origin is down to one request at a time (#377).

    Pin at open, then five seconds of playback:

    [AVIOReader] pump conn start gen=1 offset=0 len=32MB
    [AVIOReader] Cached resolved URL host=<edge>
    [AVIOReader] pump gen=1 first data after 717ms
    

    Paused for 332 s. The pump had already ended its connection at the window's high water, so nothing of ours was held at the origin across the pause:

    [AVIOReader] pump window high water: 16MB ahead; ending the connection, will re-request at the frontier once the consumer drains
    [HLSSegmentProducer] #65 backpressure PARK (advance) head=26 target=16 ... parked=332s (consumer paused; wedge detection suspended)
    

    Resume. The first request to the pinned URL is refused, and the ladder walks exactly as written:

    [AVIOReader] pump gen=5 rejected response status=509 at offset 84909512
    [AVIOReader] pump replacing a faulted connection at offset 84909512 with 5902KB of read-ahead left (streak=1 status=509, next attempt in 1.0s)
    [AVIOReader] pump gen=6 rejected response status=509 at offset 84909512
    [AVIOReader] pump replacing a faulted connection at offset 84909512 with 3342KB of read-ahead left (streak=2 status=509, next attempt in 2.0s)
    [AVIOReader] pump gen=7 rejected response status=509 at offset 84909512
    [AVIOReader] Dropped resolved URL cache (rate-limited x3 through pinned URL)
    [AVIOReader] pump replacing a faulted connection at offset 84909512 with 1038KB of read-ahead left (streak=3 status=509, next attempt in 4.0s)
    [AVIOReader] pump conn start gen=8 offset=84909512 len=32MB
    [AVIOReader] Cached resolved URL host=<edge>
    [AVIOReader] pump gen=8 first data after 417ms
    

    About 12.5 s of media time from the first 509 to first data on the re-resolved connection. Player side across that window: stall=0 drop=0+0 keepUp=y empty=n, forward buffer never under 4.0 s (its normal sawtooth is 4–8 s under the 16 MB high water), and producerRestartCount stayed at 1 — no producer restart. The heal was the reader's own, in place. In the pre-fix trace the same shape was ~60 s of frozen picture, and it only ended because the producer restarted with a fresh demuxer that re-resolved as a side effect.

    The answer to your question, and not the one I expected: the fresh target is the same host. <edge> before the drop and after it, and that host answered the re-resolved request in 417 ms after refusing three direct ones over 11 s. The following 14 minutes then ran through the re-pinned URL with first data of 38–134 ms per generation (gen=9 … gen=57, 535 MB fetched, no further 509).

    So on this origin the pinned target was never the wrong address. What died across the idle was the authorization behind it: the edge refuses a request for that URL which has not just arrived through the portal, and walking the chain again re-blesses it. The grace bound is what discovers that — the target's identity is not the signal, the round trip through the source is.

    One suggestion out of that, take it or leave it. The reader already knows the gap since the last byte on this origin, since it is the one that ends the pump connection at the high water. A pin that has not been used for, say, a minute could be spent through the source URL on its first request rather than tried directly. Here that turns 12.5 s into 0. It does not fight #307's reason for the keep-pin: after a long idle there is no in-flight request whose slot a portal hit would compete with. The 12.5 s were free this time only because 16 MB of runway absorbed them — the same pause taken right after a seek would be visible.

  5. superuser404notfound commented on Aug 17, 2026

    @superuser404notfound
    Owner

    Thank you for the retest, and for measuring the heal rather than just reporting that it worked. producerRestartCount staying at 1 is the part that says the reader healed itself in place, which is what the change was for; before it, the only thing that ever re-resolved was a fresh demuxer after a restart.

    The same host is the answer, and it is a better one than the question deserved. The three shapes that line of reasoning had room for were: the source refused the re-resolve, the source handed back the target just dropped, or a genuinely fresh target refused, with only the last one meaning the origin meters us. What the trace shows is the second one, and it is not the degenerate case it looks like: the same edge, refusing a request that has not just come through the portal and serving one that has, 417 ms later. A lease, not an address. That is worth knowing beyond this origin, because "check whether the target changed" would have read as "the pin was never the problem" on every panel that behaves this way.

    It also settles a design question in the diagnostics queued on main for #377: the refusal line compares the responding target on the origin key rather than on the whole URL, precisely so a re-minted link for the same host reads as "the target this session dropped and the source minted again" instead of as a fresh one.

    The suggestion is in, in a smaller form

    Filed as #392, with a PR open.

    The reasoning about #307 holds and is the reason it can be done at all: the keep-pin rule exists for a slot that lingers from a connection this reader has just replaced, and after a long idle there is no such slot, because the pump ends its connection at the window high water and a paused reader holds nothing at the origin.

    What it does not do is spend the pin through the source preemptively. That pays a portal round trip on every resume after an idle, including the common one where the lease is still alive, and the trace prices that: 717 ms at open against 38 to 134 ms through the pin. Instead the idle collapses the grace. Past a minute without a single byte off the network, the first rate-limited refusal drops the pin rather than the third, and the re-resolve is not paced behind a backoff charged to an address it is no longer using. A live pin pays nothing, since nothing changes about how a healthy request is issued; a dead one costs one refusal round trip plus the re-resolve instead of the 12.5 s here.

    Two things came out of writing it that are worth naming:

    • The idle has to be measured on its own clock. The reader already had a last-delivery timestamp, but it is rebased when a connection starts, so at the moment a refusal is judged it always reads as fresh. The new one is stamped wherever bytes cross the network and nowhere that serves from memory, which is the same distinction the streak-reset fix in your report turned on.
    • The detour cache's fetch arm goes through the pinned target too and carried no pin rung at all, so a dead lease discovered there could only be given up on, never re-resolved. That is the arm a backward read after a long pause lands on, which is close to the case you flagged as the one where the 12.5 s would not have been free.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions