Skip to content

A refused source (HTTP 403 on every GET) reaches the host as "Invalid data found when processing input" and disables the tail prefetch for the origin #378

Closed

Description

@tschuegy

What happened

An Xtream panel behind a portal's 302 answered every GET for a VOD .mkv with 403 for about twenty seconds (its one-connection slot was still held), while a HEAD came back 200 with Content-Length: 0. The reader's log, in order:

[AVIOReader] pump tail prefetch issued bytes=-65536
[AVIOReader] pump conn start gen=1 offset=0 len=32MB
[AVIOReader] pump tail prefetch rejected after 762ms: status=403 (no suffix range support); not asking this origin again this session
[AVIOReader] pump gen=1 rejected response status=403 at offset 0
[AVIOReader] Data connection resolved no size, falling back to probe
[AVIOReader] Range probe (bytes=0-) didn't yield a size
[AVIOReader] Cached resolved URL host=…
[AVIOReader] File size: 0 bytes (HEAD fallback)
[AVIOReader] Range probe (bytes=0-1) didn't yield a size
[AVIOReader] no probe resolved a size, streaming mode (forward-only)
[AVIOReader] Streaming started: 1325105.mkv
[AVIOReader] Streaming ended
[AetherEngine] probe failed (Demuxer: open failed (Invalid data found when processing input (-1094995529))); proceeding without criteria
…
state = .error("Failed to load: HLSVideoEngine: open failed (Demuxer: open failed (Invalid data found when processing input (-1094995529))))
errorInfo = sourceOpenFailed, underlyingDomain = "AetherEngine.HLSVideoEngine.HLSVideoEngineError", underlyingCode = 0

Same sequence on all four opens (probe + session, twice through the host's retry), then the host showed its "unsupported format / invalid video data" copy for what was a refused connection.

Why

  1. The forward-only streaming GET never looks at the status. StreamingDelegate.didReceive calls completionHandler(.allow) unconditionally (AVIOReader.swift:3313 on 6.26.0), so the 403 error page is appended to streamBuffer and readStreaming hands it to FFmpeg, which reports AVERROR_INVALIDDATA for what was a refusal. The 403 the data connection had already been refused with (persistentReceivedResponse) is kept only as the Int connStatus and then read by open() as "resolved no size" (:691), so the status is lost before the probe ladder even starts.
  2. Machine-readable companion to .error(String) so a host can classify a failure #376's classification cannot carry it. PlaybackErrorKind has no HTTP-status kind, and the underlying error is a Swift enum, so underlyingCode is 0. A host cannot tell "the origin refused" (retry later, another device holds the slot, subscription) from "the file is corrupt".
  3. One 403 disables the tail prefetch for the origin for the process lifetime. TailPrefetchDelegate takes ANY non-206 as status=… (no suffix range support) and SuffixRangeSupport latches it (VOD cold-start pays a mandatory sequential head→tail→re-anchor round trip on non-fast-start MP4 sources — request for parallel fetch or moov-offset hint #281 / 6.5.5). A 403 during a connection-cap window, a 429 or a 5xx says nothing about suffix ranges, but the origin is never asked again — on an MKV that is the tail read every later open pays for.
  4. After the 403 at byte 0 the reader still issues the HEAD and bytes=0-1 probes, which the same origin answers the same way; on a one-slot panel those are three more connections against a slot that is already full.

Proposal (PR to follow)

  • StreamingDelegate hangs up at the header on anything but 200/206 and records the status; open() fails typed with a new AVIOReaderError.httpStatus(Int) (the AE#140/AE#154 shape), which HLSVideoEngine.openFailure(from:) passes through like the HLS classifications, and load() publishes as a new PlaybackErrorKind.sourceRefused with underlyingCode = the status (additive; the struct is string-backed for exactly this).
  • After a 401/403/404/410 on the data connection at byte 0, skip the HEAD / bytes=0-1 probes; still try the one unranged GET (an origin that refuses Range but serves a plain GET plays forward-only, one that refuses both fails with its status). 5xx and 429/503/509 keep the ladder.
  • The suffix-range denial latches only on the origin's answer to the range FORM (a 200 that ignored it, a 416); 401/403/404/429/5xx neither latch nor count as a transport strike.

Tested against a scripted loopback origin (HEAD 200/0, GET 403 with an error page); on-device: Apple TV 4K (tvOS 26), Xtream VOD MKV behind a 302, max_connections=1 panel.

Activity

  1. superuser404notfound commented on Aug 17, 2026

    @superuser404notfound
    Owner

    Reopening for the retest, not because anything is missing: the "Fixes #378" in #379 closed this on merge, and the on-device confirmation against the reported panel is still outstanding.

    State on main:

    Once it ships, the trace to look for on the reported origin is source refused: HTTP 403; failing the open typed instead of the four Invalid data found when processing input opens, and $errorInfo carrying kind sourceRefused with underlyingCode 403 during the slot-held window.

  2. superuser404notfound commented on Aug 17, 2026

    @superuser404notfound
    Owner

    Released in 6.29.0, together with the #380 and #388 work. Thank you for the report and the PR.

    PlaybackErrorKind.sourceRefused is public from this version, with the HTTP status in underlyingCode, and a 429/503/509 on the same request publishes sourceRateLimited instead.

  3. tschuegy commented on Aug 17, 2026

    @tschuegy
    ContributorAuthor

    Closing the loop on the retest you reopened this for: the reported origin cannot produce the shape any more, and the reason is on my side, not the engine's.

    The 403 was my own aggregator, which sits in front of the panels, routing this episode to the wrong upstream portal — the series lives on one portal and the request went to another, which answered exactly as it should. I deployed an episode-to-portal redirect and since then every series and film plays, so there is no longer an origin in my setup that refuses a GET. The disappearance is the confirmation of that fix, and it also means the original report was never a rights or auth problem: it was a misroute wearing a 403.

    So I verified the typed path against a synthetic origin instead: an Xtream stub whose portal answers normally and whose media route answers every GET with a chosen status and an HTML error page as the body — the part that used to reach FFmpeg. On 6.30.0, iOS 26.5 simulator:

    403

    [AVIOReader] pump gen=1 rejected response status=403 at offset 0
    [AVIOReader] pump data connection refused status=403 at offset 0; skipping the size probes, trying one unranged GET
    [AVIOReader] pump streaming GET refused status=403; hanging up at the header
    [AVIOReader] pump source refused: HTTP 403; failing the open typed
    

    and at the host:

    kind=sourceRefused httpStatus=403
    

    509, same route, one file change on the stub:

    [AVIOReader] pump streaming GET refused status=509; hanging up at the header
    [AVIOReader] pump source refused: HTTP 509; failing the open typed
    kind=sourceRateLimited httpStatus=509
    

    No Invalid data found when processing input anywhere in either run — the error page never enters the buffer. Both the refusal and the metered variant carry their status through underlyingCode, which is what the host needs: my failure copy is chosen from the status, so a 403 now reads "the provider refused this stream (HTTP 403), check your subscription" and a 509 reads "your provider's connection limit has been reached", where before both were the same generic load failure. On a portal that declares one connection the 403 keeps the connection-limit wording, which is the reading you and I settled on in #377.

    Happy for you to close this. If a refusing origin ever turns up in my setup again I will bring you a real trace, but I would rather not manufacture one by breaking my own routing on purpose.

  4. superuser404notfound commented on Aug 17, 2026

    @superuser404notfound
    Owner

    Retest accepted, and the synthetic origin is the better witness here anyway. Once the panel stopped refusing, a run against it could only have shown that the misroute is gone, not that the typed path works. A stub whose media route answers with a chosen status and an HTML body reproduces precisely the part that used to reach FFmpeg, which is the thing under test.

    Both traces match main line for line: AVIOReader.swift:2870 is the hang-up at the header, :881 the skipped size probes after a refusal at byte 0, :967 the typed open failure, and PlaybackErrorInfo.swift:148 is the split that sends 429/503/509 to sourceRateLimited and everything else to sourceRefused, both carrying the status in underlyingCode.

    Worth recording the diagnosis for anyone who lands here later: the 403 was truthful for the request that was actually made, and said nothing about rights or subscription. That is one more argument for handing the host the status instead of a sentence. "The provider refused this stream (HTTP 403)" is a statement about the answer, and the host can pick its wording from the panel's declared connection limit, while a message baked into the engine would have had to guess at a cause it cannot see.

    Closing. Thank you for the report, for the PR, and for bringing a measurement rather than an assumption once the original origin could no longer produce the shape.

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