Skip to content

fix(live): the HLS ingest rides out an origin's refusals instead of ending the session - #778

Merged
superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
jpsts:fix/live-ingest-refusal-retries
Oct 15, 2026
Merged

superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
jpsts:fix/live-ingest-refusal-retries

Conversation

@jpsts

@jpsts jpsts commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

An IPTV panel that limits an account's connections answers a live playlist refresh with 509 while another device on the account holds the last slot. It goes on refusing the session it evicted, while a fresh session from the loaded URL is admitted at once. The live HLS ingest handles that badly in two ways, and together they turn a recoverable refusal into a lost session plus a 10 s wait.

  1. The refresh ladder gives up early. It retries 1, 2 and 4 s apart, then goes terminal at 12 s, while the consumer still holds tens of seconds of media. On the software path, the terminal ends the session.
  2. Every refusal arms OriginRequestBudget's pacer for the origin (a quiet of up to 15 s, then a 2 s token bucket), and halves its request budget for the rest of the process. The host's reload, or the native path's reopen, then waits up to 10 s for its first request, against an origin that would answer it at once.

From the field

The setup: an IPTV host on macOS 26 playing a live HLS source whose loaded URL redirects to a tokenized session URL, on a connection-limited account, with a second device on the account changing channels. Times are relative to the first refusal.

Before, on the software path:

 +0.0 s  [HLSIngest] playlist refresh failed (attempt 1: playlistUnreachable(509)); retrying in 1s
 +2.0 s  [HLSIngest] playlist refresh failed (attempt 2: playlistUnreachable(509)); retrying in 2s
 +6.1 s  [HLSIngest] playlist refresh failed (attempt 3: playlistUnreachable(509)); retrying in 4s
+14.1 s  [HLSIngest] terminal: playlistUnreachable(509)
+14.1 s  [SWHost] live reader read failed: Demuxer: read failed (Operation not permitted (-1))
         (playback ran on from the buffer until here)
+14.2 s  host reloads
+24.2 s  [OriginBudget] ingest-playlist proceeded without waiting the pacer out after 10004ms
+29.3 s  [HLSIngest] joined 3 segment(s), ~29s behind the live edge
+29.6 s  [AetherEngine] #361 startup 8/8 presenting

That was 15.5 s of black, 10 of them in the pacer. On the native path the same ladder ended in a reopen that also waited 10 s in the pacer: the terminal, then 10.5 s to the pacer's line, then the reopen succeeded 15.2 s after the terminal.

With the steady retries and no pacer, before the re-resolve on refusal was added, on the software path, in two refusal windows:

Window Session URL refused for Buffer carried playback for Fresh session joined Picture back after the buffer ran out
1 17.6 s 15.6 s 0.25 s 2.8 s
2 27 s 25 s 0.25 s 3.0 s
  • Retry cadence: the refused refresh went out every 1.05 s.
  • How each window ended: the host's own reload. Its fresh session from the loaded URL was admitted at once, while the session URL was still being refused. That is why this change re-resolves after two refusals.

With this change, on the native path: 15 refusal windows in 3 minutes, each ended by a fresh session 2.3 to 2.6 s after its first refusal, with no rebuffer, no stall and no terminal.

+0.0 s  [HLSIngest] playlist refresh failed (attempt 1: playlistUnreachable(509)); retrying in 1.0s
+1.1 s  [HLSIngest] playlist refresh failed (attempt 2: playlistUnreachable(509)); retrying in 1.0s
+2.1 s  [HLSIngest] session URL refused 2 times; asking the loaded URL for a fresh one
+2.3 s  [HLSIngest] playlist refresh recovered after 2 failed attempt(s) in 2.3s through the loaded URL

One of the 15 fresh sessions came back with its timestamps restarted. The producer rebased it, then its no-cut stall heuristic ("likely SSAI ad pod") asked the host to retune, which cost a 1.24 s reload. That heuristic is outside this change.

The change

  • Steady retries: a refused or unreachable refresh (429, 5xx, transport) is asked again every second, or after the origin's Retry-After up to 5 s, for up to 60 s. That budget outlasts what a session holds ahead of the playhead, so the host's own stall handling decides once that runs dry. A refused segment gets the same, after its two quick retries.
  • A fresh session URL: when the loaded URL led to the media playlist through redirects, a session URL refused twice in a row is asked for afresh through the loaded URL. One that answers as gone (a 4xx other than 429 and 408) is asked for at once. The playlist tracker follows MEDIA-SEQUENCE, so the segments continue where they left off. A source with no separate session URL still ends on a gone playlist.
  • No pacer from these refusals: the live ingest's refusals no longer arm the pacer or lower the request budget. Its own steady retry, at most one request a second while refused, is its pacing. A ceiling the host declares, or one another path learns, still binds it.

I know the pacer and the backoff exist for origins that punish rapid retries (#307, #377, #380). If you'd rather keep the live ingest on the books, I'm happy to rework that part instead, for example as a quiet capped at the origin's Retry-After or about 1 s, or as a LoadOptions switch.

Tests

  • HLSLiveIngestRefusalTests, new, in a loopback origin:

    • a refused refresh: four 509s, then served;
    • a refused segment: four 509s, then served;
    • a session URL that stays refused;
    • a revoked session URL;
    • a gone direct playlist;
    • the retry waits and the refresh URL choice.

    The refused refresh, refused segment and revoked session URL cases fail on main: terminal, and the pacer armed.

  • Suites run: DocumentedConstantsTests, PublicAPIDocumentationTests and the ingest suites pass.

  • Full suite: passes apart from HLSLocalServerSlowPeerTests "LAN peers cannot take the slots kept for loopback". It times out the same way on unmodified main on this machine, where the test runner cannot connect to its own LAN address.

Test plan: macOS 26. A live HLS source whose loaded URL redirects to a tokenized session URL, behind a connection-limited IPTV panel, with a second device on the account changing channels. Measured on the software path before the change, and on the native path with it.

…nding the session

An IPTV panel that limits an account's connections answers a live playlist refresh with 509 while
another device holds the last slot, and goes on refusing a session it evicted while a fresh session
from the loaded URL is admitted at once. The ingest retried 1, 2 and 4 s apart and went terminal at
12 s (on the software path, the end of the session), and each refusal armed the origin's request
pacer, so the host's reload waited up to 10 s for its first request.

- A refused or unreachable refresh (429, 5xx, transport) is asked again every second, or after the
  origin's Retry-After up to 5 s, for up to 60 s; a refused segment likewise, after its two quick
  retries.
- A session URL the loaded URL led to through redirects is asked for afresh through the loaded URL
  once refused twice in a row, or at once when it answers as gone (a 4xx other than 429 and 408).
  The tracker follows MEDIA-SEQUENCE, so the segments continue where they left off.
- The live ingest's refusals no longer arm OriginRequestBudget's pacer or lower its request budget;
  a ceiling the host declares or another path learns still binds it.

Tests: HLSLiveIngestRefusalTests.
@superuser404notfound
superuser404notfound merged commit b5d9a1e into superuser404notfound:main Oct 15, 2026
superuser404notfound pushed a commit that referenced this pull request Oct 15, 2026
 follow-up)

PR #778 gave every failed refresh and segment fetch 60 s of steady
retries, transport errors and any 5xx included. A dead channel or a lost
network then sat behind a spinner for up to a minute (measured 59.7 s
on the loopback) before the host's reopen or fallback got a turn.

Only the refusal statuses (429, 503, 509) get the 60 s budget now;
anything else keeps the 12 s that bridges a single CDN timeout. A retry
loop keeps the longest budget it has seen, so one transport blip inside
a refusal window does not end it.

The playlist Retry-After is also cleared before every attempt, so a
value left over from an earlier refusal is never applied to a later one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
@superuser404notfound

Copy link
Copy Markdown
Owner

Thank you, this is an excellent PR. The field logs made the failure easy to follow, and the before/after numbers (15 refusal windows in 3 minutes, each bridged in about 2.5 s) are exactly the evidence this needed. Merged in b5d9a1e, full suite green on top of current main.

One follow-up landed on main in a16ad60:

  • Only a refusal gets the minute. The 60 s budget now applies to the refusal statuses (429, 503, 509). A transport error or any other 5xx keeps the old 12 s budget, because a dead channel or a lost network otherwise sat behind a spinner for up to a minute (59.7 s on the loopback) before the host's reopen or fallback could act. A retry loop keeps the longest budget it has seen, so one transport blip inside a 509 window does not end it. New test: a broken refresh that is not a refusal ends on the short budget, which fails without the change.
  • Retry-After is cleared before every playlist attempt, so a value left from an earlier refusal is never applied to a later one.

On the pacer question: keeping the live ingest's own refusals off the books is fine. A 15 s quiet is never the right answer on a live path, and the steady 1 s retry is a reasonable pace on its own. No LoadOptions switch for now.

One question, if it is easy to check on that panel: are the segment URLs bound to the session too (e.g. /hls/<token>/seg.ts), and did a segment fetch ever get the 509 in your captures? Right now a refused segment retries against the evicted session for up to 60 s and does not ask the loaded URL for a fresh one. If panels do refuse segments of an evicted session, that path should re-resolve as well, but we would rather see it happen before building it.

Not released yet; it will go out with the next AetherEngine tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants