Repository navigation
Description
What happened?
A remote, non-faststart MP4 (~820 MB, trailing moov, coarsely interleaved) never starts playing. After the header and trailing-moov reads, the persistent AVIO reader tears down and reopens its HTTP connection on nearly every demuxer seek (Persistent conn gen=N ended with error: cancelled); the origin eventually returns 429 and the read loop spins without making forward progress. A faststart file from the same origin plays fine. Expected: read the header/index and begin playback.
Steps to reproduce
- Serve a remote MP4 over HTTP(S) that is non-faststart (trailing moov) and coarsely interleaved (track data regions tens of MB apart), so the demuxer must seek between distant file regions during avformat_find_stream_info / index parsing.
- Load it through the persistent reader path (known Content-Length, prefetch enabled).
- Watch the [AVIOReader] demux logs: a reconnect-per-seek storm, climbing gen=N, then status=429. Playback never starts.
AetherEngine version or commit SHA
3.13.2
Host app
Custom / my own integration
Platform
macOS
OS version
27 beta
Device / chip
m2 / a19 pro
Playback path
Native AVPlayer
Source media (for playback bugs)
MP4 (mov,mp4), 820,727,423 bytes, progressive HTTP(S) download. Non-faststart: moov near EOF (first seek to offset ≈820,001,011). Coarsely interleaved: parser ping-pongs between ≈0–12 KB, ≈21 MB, and the moov region. FFmpeg also logs stream 0, timescale not set during parse. (Codec details via ffprobe or CDN URL available on request.)
Error codes / log lines
[demux] [AVIOReader] File size: 820727423 bytes (Range probe)
[demux] [AVIOReader] Persistent conn start gen=1 offset=0
[demux] [AVIOReader] Persistent conn gen=1 ended with error: cancelled
[demux] [AVIOReader] Persistent conn start gen=2 offset=820001011 # trailing moov
[ffmpeg] [mov,mp4,m4a,3gp,3g2,mj2] [warning] stream 0, timescale not set
[demux] [AVIOReader] Persistent conn start gen=3 offset=176
[demux] [AVIOReader] Persistent conn gen=3 ended with error: cancelled
[demux] [AVIOReader] Persistent conn start gen=4 offset=21048761
[demux] [AVIOReader] Persistent conn gen=4 ended with error: cancelled
[demux] [AVIOReader] Persistent conn start gen=5 offset=819972848
[demux] [AVIOReader] Persistent conn start gen=6 offset=458
... # gen keeps climbing
[demux] [AVIOReader] Persistent conn ended at offset 21051909 status=429, reconnecting (streak=1 ...)
[demux] [AVIOReader] Persistent conn ended at offset 21051909 status=429, reconnecting (streak=2 ...)
Anything else
A small detour block cache that serves these random-access reads through the existing pooled fetchChunk / chunkSession (keep-alive) path instead of tearing down the streaming connection: 4 MB aligned blocks, ~8-block / ~32 MB LRU, gated to !isLive && fileSize > 0. The backward branch serves from the cache (pooled fetch on miss) so the streaming connection stays pinned; the far-forward branch serves only if already cached, else keeps seekReconnect; once detour reads run sequentially past ~8 MB it re-anchors the streaming connection. Each block is fetched once over a reused connection, so the parse ping-pong becomes cache hits and the storm collapses to the two legitimate reconnects (open + moov).
Why it doesn't regress other paths. Sequential playback hits the window fast path and never enters the backward/far-forward branches, so the cache is never consulted or populated (no overhead, no behavior change). Live and unknown-size sources are gated out. Genuine forward seeks keep seekReconnect; the re-anchor returns sustained sequential reads to the streaming window. It reuses fetchChunk/chunkSession, already called synchronously on the demux thread for probes/prefetch, so no new networking model; the cache is freed in close().
After the change (same file, same origin):
[demux] [AVIOReader] Persistent conn start gen=1 offset=0
[demux] [AVIOReader] Persistent conn start gen=2 offset=820001011
[demux] [AVIOReader] detour fill block=0 offset=0 size=4194304 (resident=1)
[demux] [AVIOReader] detour fill block=5 offset=20971520 size=4194304 (resident=2)
[demux] [AVIOReader] detour fill block=195 offset=817889280 size=2838143 (resident=3)
[demux] [AVIOReader] detour fill block=6 offset=25165824 size=4194304 ... # playback proceeding
Activity
chore(release): prep 4.2.1 — AVIOReader detour cache + bounded 429 re…
superuser404notfound commentedon Jun 26, 2026
Fixed in 4.2.1 (
a6f46bf).The persistent reader now serves the random-access parse reads (the header / trailing-moov / sample-region ping-pong) through the existing pooled keep-alive session, cached as 4 MB aligned blocks in a small LRU (8 blocks, ~32 MB, VOD only), instead of tearing the streaming connection down per seek. The connection stays anchored and the storm collapses to the two legitimate reconnects (open plus the one seek to the moov), exactly as you measured.
Two details beyond the original sketch:
The throttled-origin coupling you flagged is handled as #71 (shipped in the same release): the detour miss-under-429 fallback backs off and retries the pooled fetch instead of re-seeking.
Thanks for the detailed diagnosis and for validating the approach across the 820 MB / 54 GB / 67 GB files. Leaving this open until you can confirm on 4.2.1.
Release: https://github.com/superuser404notfound/AetherEngine/releases/tag/4.2.1
fix(demux): serve random-access parse reads from a detour cache, boun…
fix(demux): bound the backward-scrub detour fetch so a starved cold r…
fix(io): the other two served-from-memory branches charge the ladders…
fix(demux): only bytes that crossed the network clear the reader phase (
fix(demux): a jump back anchors the connection at the landing instead…
refactor(reader): the source cache is the reader's one byte store
feat(reader): fetches sized to the read and the link, not to fixed bl…