hls.js fMP4 init-segment retry race: stale abort cancels newer attempt (upstream #8151)

GitHub source

Evidence not classified. This page is generated from GitHub Issue #61; GitHub remains the canonical authoring and discussion source.

Source and unresolved status (checked 2026-11-23)#

Upstream: video-dev/hls.js#8151 — OPEN; 0 comments; no matching PR found by issue-number search. This does not prove that no unlinked fix exists. No upstream resolution confirmed. Reporter has a local experimental patch, not an accepted fix.

Symptom and reproducibility#

hls.js 1.7.3, Chrome, multi-level fMP4. Delay level-1 init segment by 400 ms, switch levels, then abort first media fragment once. Reporter observed 156 init requests in ~16 s, each aborted around 99 ms, never completing. With 40 ms init delay, playback resumed. Reporter reports 0.33–0.46% of level-switching views affected. These are reporter measurements, not independently replicated.

Causal hypothesis / code path#

A prior attempt's init request is aborted when a new attempt starts. Its asynchronous rejection then executes old error handlers against shared state/loader belonging to the new attempt. The old loadInitSegmentIfNeeded catch aborts the new media request and resets state to IDLE. The old _doFragLoad promise rejection reaches _loadFragForPlayback and resets again. At ~100 ms controller ticks, a slow init is perpetually restarted. This is a superseded asynchronous operation / stale completion race; source-level control flow and exact line numbers require independent confirmation on pinned commit.

Evidence ledger#

  • Upstream issue: OPEN, no comments, no PR matching #8151 in GitHub PR search (checked 2026-11-23).
  • Reporter reproduction: 400 ms delay => 156 aborts / ~16 s; 40 ms control succeeds.
  • Reporter local intervention: generation counter + silently unresolved superseded promise => 2 init requests, playback after ~0.4 s. This is not a production-safe endorsed solution; unresolved promises may leak and obscure cancellation semantics.
  • Unknown: exact latest master behavior; duplicate or unlinked PR; behavior on AVPlayer (this is hls.js, not native Apple player).

Experiment / regression matrix#

  1. Pin hls.js 1.7.3 and latest master SHA; capture FRAG_LOADING, ERROR, state transitions and HTTP aborts with monotonic timestamps.
  2. Vary init response delay: 40, 90, 110, 200, 400, 800 ms. Abort exactly once after level switch; compare no-abort control.
  3. Vary trigger: seek, ABR abandon, level switch, retryable fragment error.
  4. Test two candidate fixes separately: (A) deduplicate/reuse same init promise; (B) per-attempt cancellation tokens with guarded cleanup. Verify no orphan promise and no stale callback aborting new request.
  5. Assert exactly one active init request per identity, no unbounded retry, eventual first frame, correct errors for genuine network failures, cleanup on stop/destroy, and no regressions on AES-128/FairPlay-independent paths.
  6. Compare native AVPlayer only as separate control; no inference that native AVFoundation shares this code.

Reusable insight#

Cancellation must be scoped to an operation generation. An asynchronous failure from superseded attempt N must not mutate state or abort network resources owned by attempt N+1. abort() is not equivalent to safe completion of all prior callbacks.

Next article milestone#

Confirm source-level lines at pinned SHA; implement deterministic delayed-init proxy; compare generation-guard and in-flight init reuse; report first proven divergence and reproducible trace. ROOT CAUSE NOT INDEPENDENTLY VERIFIED.

Specialized second-AI reverse-engineering prompt

Act as a senior iOS reverse engineer, AVFoundation/CoreMedia/HLS engineer, and FairPlay DRM specialist. Investigate video-dev/hls.js#8151. Determine the first proven causal divergence when a slow fMP4 init segment is repeatedly aborted after a level switch and a fragment retry. Do not conflate hls.js with native AVPlayer.

Strict evidence hierarchy:

  1. Official Apple Developer Documentation, HLS authoring specifications, RFC 8216 and applicable Apple/IETF standards.
  2. Pinned hls.js and WebKit source (repository URL, commit SHA, path, function and line range), plus verified security research when relevant. WebKit is not AVFoundation source.
  3. Sanitized HTTP traces, controller logs, reproducible physical-device/browser experiments and controlled fault injection.
  4. Explicitly labeled falsifiable hypotheses only.

Audit issue status, linked/unlinked PRs, duplicate and follow-up issues before proceeding. Trace loadInitSegmentIfNeeded, _loadInitSegment, _doFragLoad, _loadFragForPlayback, fragmentLoader.abort, initFragmentLoader.abort, fragContextChanged, and resetFragmentLoading. Construct an attempt-ID timeline showing each request's owner and all late promise callbacks. Test init delays 40–800 ms and a single deterministic abort after switching levels. Compare latest master to 1.7.3, and evaluate in-flight init reuse versus per-attempt cancellation. Check cleanup, memory retention, seek/ABR races and failure propagation. FairPlay key requests must be investigated only if the evidence shows DRM involvement; never expose keys, SPC/CKC or bypass DRM.

Deliver evidence ledger, first-divergence diagram, reproducible harness, controlled A/B results, competing-hypothesis falsification, client-only mitigations, separately labeled packaging/CDN proposals, regression tests, and publication-ready article. If not proven, state ROOT CAUSE UNVERIFIED. Never invent traces, measurements, citations, commit IDs, or publication status.