Skip to content

AVIOReader issues a redundant size probe (Range bytes=0-0 → HEAD) that the first data connection already answers #70

Closed

Description

What happened?

On every HTTP open, AVIOReader.open() calls probeFileSize() — a Range: bytes=0-0 GET — and then opens the real data connection (Range: bytes=0-) at offset 0. The persistent/streaming GET's 206 response already carries the total in Content-Range, so the standalone probe is a redundant extra round-trip. On origins that don't return a length for bytes=0-0, the probe also falls back to a second request (HEAD), so the open pays two size round-trips before the first byte is used (Range probe didn't yield a size, trying HEAD). Because the probe runs per demuxer-open (and the load path opens more than once), this multiplies and adds avoidable load that can help trip an origin's rate limiter. Expected: discover the size from the first data connection's response headers and skip the dedicated probe.

Steps to reproduce

  1. Point the engine at a remote MP4/MKV over HTTP(S) on an origin that does not return Content-Range/Content-Length for a Range: bytes=0-0 request (common behind some CDNs/proxies).
  2. engine.load(url:).
  3. Watch the [AVIOReader] logs: a Range probe … (or … trying HEAD) round-trip, immediately followed by the persistent connection's Range: bytes=0- GET to the same offset.

AetherEngine version or commit SHA

3.13.2

Host app

Sodalite

Platform

tvOS

OS version

27 beta

Device / chip

a19 pro / m2

Playback path

Native AVPlayer

Source media (for playback bugs)

MP4 (mov,mp4) and MKV over progressive HTTP(S); container-agnostic. Most visible on origins that omit length on bytes=0-0.

Error codes / log lines

[AVIOReader] File size: … bytes (Range probe)              # probe round-trip #1
[AVIOReader] Range probe didn't yield a size, trying HEAD  # round-trip #2 on some origins
[AVIOReader] Persistent conn start gen=1 offset=0          # the real GET, whose 206 Content-Range already has the total

Anything else

Proposed fix. Derive fileSize from the first data connection's response (Content-Range total on 206, or Content-Length on a from-0 200) and drop the standalone probeFileSize() for the common case; keep the Range/HEAD probe only as a fallback when the first response has no length (chunked/live → streaming mode, as today). Skipping the probe for isLive is a free win on its own (it otherwise burns the full Range timeout on transcode endpoints that reject Range).
The one constraint: the reader selects its mode (persistent/seekable/streaming) from fileSize before the first read, and usePersistentReader/isStreaming are recomputed from fileSize on every read(). Folding size-discovery into the first connection therefore wants an explicit mode latch decided at open time. That refactor is engine-internal, which is why I'm filing it here rather than working around it in the host.
Why it won't regress normal playback. Worst case (no length on the first response) is identical to today — fall back to the existing probe/HEAD. Best case skips 1–2 round-trips. .strm/live with no length still resolve to streaming mode by the same path.

Activity

  1. ghost added
    bug
    on Jun 26, 2026
  2. superuser404notfound commented on Jun 26, 2026

    @superuser404notfound
    Owner

    Fixed in 4.2.3.

    The dedicated probeFileSize() round-trip is gone for the playback path. AVIOReader.open() now starts the persistent Range: bytes=0- data connection first and folds the total straight out of its first response (206 Content-Range, or Content-Length on a from-0 2xx), so the common case opens with zero extra round-trips. Live skips it as well, since its result was discarded anyway and the probe otherwise burned the full Range timeout on transcode endpoints that reject Range.

    The size oracle moving onto the data connection had one constraint worth calling out, because it is exactly the rate-limiter interaction you flagged: if it became the only size path, a transient open-time 429 (or a slow-header origin, or one whose length only comes via HEAD) would lose the independent probe's resilience and downgrade the whole session to seekless streaming. So when the data connection resolves no usable size, the open falls back to the exact prior probe path (Range: bytes=0- then HEAD) on a separate connection and budget:

    • a transient 429 recovers to the seekable persistent reader once it clears,
    • a slow-header origin gets a fresh probe budget instead of being downgraded at the first-byte deadline,
    • a HEAD-only length still resolves and stays seekable,
    • only a genuinely length-less source (no Content-Range, no Content-Length) streams, as before.

    Your bytes=0- over bytes=0-0 observation is in too: the persistent connection already used bytes=0-, and the remaining still-extraction probe now uses it as well, so the single-byte form that some origins special-case (omitting the length and then 429-ing the HEAD) is no longer on any path.

    Thanks for the precise diagnosis, the real-world Range probe didn't yield a size, trying HEAD -> HEAD failed (HTTP 429), streaming mode chain, and the confirmed one-shot probe shape. It made the root cause and the safe scope unambiguous.

  3. ghost closed this as completedon Jun 26, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions