Skip to content

fix(io): fail closed when an HLS playlist is misrouted onto the raw live path (#140) - #144

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/ae140-hls-playlist-raw-live-misroute
Jul 19, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/ae140-hls-playlist-raw-live-misroute

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Fixes #140.

Problem

load(url: m3u8, options: LoadOptions(isLive: true)) without nativeRemoteHLS bypasses both documented HLS entry points (loadRemoteHLS / HLSLiveIngestReader) and routes the playlist URL onto the raw-byte live reader (AVIOReader, endless-feed mode).

A live origin serves the finite ~497-byte #EXTM3U body at HTTP 200 and closes the connection. The endless-feed reader read that as a dropped live stream and reconnected, re-fetching the same body forever. The reconnects looked productive (a full body at 200, and every find_stream_info probe seek reset the unproductive-reconnect streak via seekReconnect), so the #71 give-up counters never tripped. avformat_open_input never returned, and load() sat at .loading with no terminal state (reporter observed 262 reconnect cycles over 5.75 min). The raw-TS live path fails closed correctly because a dead TS source returns a real connection error; a healthy static playlist at HTTP 200 slips past every give-up heuristic.

Fix

Detect the misroute at the byte source, not in the give-up counters (which are structurally blind to a productive-looking playlist re-serve). After the persistent connection delivers its first window, the reader snapshots the leading bytes and fails closed when they begin with the HLS playlist tag #EXTM3U (tolerating a UTF-8 BOM and leading whitespace). A raw media container never opens with # (TS syncs on 0x47; MP4/MKV open with binary box/EBML markers), so the prefix is an unambiguous signal that an m3u8 was handed to the wrong API. The reader throws before the reconnect loop is entered.

load() surfaces it as a new typed, catchable AetherEngineError.hlsPlaylistOnRawLivePath (with an actionable LocalizedError description pointing the caller at nativeRemoteHLS / HLSLiveIngestReader), reusing the existing live fail-closed seam.

Verification

  • End-to-end on the exact .url + isLive misroute via a local static-playlist HTTP fixture: pre-fix hung; post-fix terminates in 0.03s with the typed error and an actionable .error state, no reconnect cycles.
  • Unit tests cover the byte classifier (media/master playlist, BOM, whitespace, TS sync, MP4 ftyp, bare #EXTINF, truncated prefix, empty).
  • Full suite: 730 tests pass. swift build (Swift 6 complete concurrency) + tvOS Simulator build green.

API surface (MINOR)

Adds public case AetherEngineError.hlsPlaylistOnRawLivePath and a LocalizedError conformance on AetherEngineError → 5.9.0.

🤖 Generated with Claude Code

…ive path (#140)

load(url: m3u8, options: LoadOptions(isLive: true)) without nativeRemoteHLS
routes the playlist URL onto the raw-byte live reader (AVIOReader). A live
origin serves the finite #EXTM3U body at HTTP 200 and closes the connection;
the endless-feed reader read that as a dropped live stream and reconnected,
re-fetching the same body forever. Those reconnects looked productive (a full
body at 200, and every find_stream_info probe seek reset the unproductive
streak via seekReconnect), so the #71 give-up counters never tripped,
avformat_open_input never returned, and load() sat at .loading with no
terminal state (reporter: 262 reconnect cycles over 5.75 min).

The raw-byte reader now snapshots the first window bytes of a live source and
fails closed when they begin with the HLS playlist tag (#EXTM3U, tolerating a
UTF-8 BOM and leading whitespace). A raw media container never opens with '#'
(TS syncs on 0x47; MP4/MKV open with binary box/EBML markers), so the prefix
is an unambiguous misroute. The reader throws before the reconnect loop is
ever entered; load() surfaces it as the new typed, catchable
AetherEngineError.hlsPlaylistOnRawLivePath with an actionable message pointing
the caller at nativeRemoteHLS / HLSLiveIngestReader.

Verified end-to-end via a local static-playlist HTTP fixture on the .url +
isLive path: pre-fix hung; post-fix terminates in 0.03s with the typed error.
Unit tests cover the byte classifier. Full suite: 730 tests pass.

Reported by cmcpherson274.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01UgFNKdx4Mq3zgCawKzAa6w
@superuser404notfound
superuser404notfound merged commit 5262771 into main Jul 19, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/ae140-hls-playlist-raw-live-misroute branch July 19, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant