You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SoftwarePlaybackHost.seek runs the deadline-free Demuxer.seek on the main actor — a remote source can block the main thread for seconds (field App Hangs) #254
Two App Hangs in the field, both a seek on the software path against a remote source, both with the main thread blocked in avformat_seek_file.
Verified present at eb4facb (post-6.0.2), not just on the build that reported it.
Field evidence
Two crash-reporter App Hang events, "Fully Blocked", 4.4 s and 5.2 s, 2026-07-28T19:43:42Z and 19:47:57Z. Apple TV 4K 3rd gen, AetherEngine 5.19.1, a remote HTTP source over a WAN link, software decode path. Reported by a remote user, not a bench.
Host-side corroboration from the same window: a seek burst, 20+ serialized relative seeks of +10 s each between 19:42:00 and 19:42:10Z. The mutex frame is the second seek queuing; the first one is what is actually blocking.
Mechanism
SoftwarePlaybackHost.seek(to:) calls dem.seek(to: seconds) — Demuxer.seek(to seconds: Double), which takes accessLock and runs avformat_seek_file plus avformat_flush with no read deadline.
seekBounded exists directly below it and its own doc comment names this exact failure:
Needed for VOD cue prewarm: missing/truncated MKV Cues causes matroska to degrade from "1-2 byte-range reads" into a linear half-file scan on a remote 70+ GB source (de-facto hang). Only AVIOReader honours the deadline.
So the hazard is known and the mitigation is already written; the software host just does not use it.
The part that makes it an App Hang rather than a stall
SoftwarePlaybackHost is @MainActor. The synchronous, deadline-free seek therefore runs on the main thread. That is why the reporter sees a frozen UI rather than a playback stall, and it means these are two independent problems:
No deadline — a degraded seek can scan indefinitely.
Main actor — even a bounded seek that takes the full 8 s budget is 8 s of frozen UI. Fixing only the deadline converts an unbounded hang into a bounded one.
A burst makes both worse: every subsequent seek serializes on accessLock behind the first, so N slow seeks compound instead of the later ones superseding the earlier.
Other callers of the unbounded variant
Not implicated by these reports, listed because they share the property:
HLSVideoEngine+SegmentPlanning.swift:245 — demuxer.seek(to: 0) under rewindBeforeScan
AetherEngine.swift:2656 — probe.seek(to: 0) after the interlace sample probe
What I cannot confirm
The asset's container. The rating key in our telemetry no longer resolves, so I cannot state it was Matroska, and the Cues degradation the seekBounded comment describes is Matroska-specific. In our deployment the software path predominantly serves AV1/VP9, which is Matroska-family, so it is very likely — but treat it as unproven. Two events, no local reproduction; the seek burst is reproducible, the slow remote seek is not on demand.
A client issuing 20 seeks in 10 seconds is arguably also ours to fix, so I am reporting the burst as the trigger rather than as the cause.
Confirmed and fixed in #256 (839b64c). Thanks for the report, the two hang stacks plus the seek-burst window from the same period were enough to pin this without a local repro.
One correction to the mechanism, because it changes what the fix has to be.
The report reads the mutex frame as the second seek queuing behind the first. That cannot be what happened: SoftwarePlaybackHost is @MainActor (SoftwarePlaybackHost.swift:12) and the VOD branch of seek(to:) had no suspension point between the generation bump and dem.seek(to:), so two host seeks can never overlap. The main actor serialized them.
The lock holder was the demux loop. Demuxer.readPacket takes accessLock and holds it across the whole of av_read_frame (Demuxer.swift:992-998), and that loop runs on demuxQueue, so on a remote source the lock is held for the length of one network read, up to AVIOReader.connStallTimeout (20 s). 4.4 s and 5.2 s sit comfortably inside that. The subtitle side readers are not candidates here, they open their own Demuxer instances.
The consequence: swapping seek for seekBounded would not have prevented either hang. seekBounded arms its read deadline after accessLock.lock(), on the far side of the wait that actually blocked. The missing deadline is a real second hazard, it is just not the one these two events evidence. The main-actor isolation is.
So the fix is both, in that order. Demuxer gained an async seekBounded that runs on a caller-owned serial queue and reports landed / stalled / superseded; both @MainActor hosts now await it. The supersede predicate is evaluated on that queue immediately before the FFmpeg call, so the burst that triggered this collapses onto its last target instead of paying one lock wait per seek. That covers the client-side half you offered to own.
Two things the report did not cover that turned out to be the same defect:
SoftwarePlaybackHost.load and AudioPlaybackHost.load ran their startPosition resume seek the same way, inline on the main actor. That is every resume into a remote source, not just a scrub.
AudioPlaybackHost.seek is the same shape without the video half.
The two other unbounded callers listed in the report are untouched, and neither is a hang risk: HLSVideoEngine is @unchecked Sendable, so rebuildHEVCExtradataWithInBandParameterSets runs on a producer thread, and AetherEngine.swift:2656 is already inside a Task.detached.
Since the seek is now a real suspension point, two follow-on cases are handled in the same change rather than left to surface later: the time tick is gated while a reposition is in flight, because the synchronizer still carries the pre-seek anchor and would otherwise walk the published position over the target; and both hosts re-check teardown after the await. A reposition that spends its 8 s budget closes the #38 ticket as .stalled rather than reporting a landing the engine cannot back up.
Leaving this open for a retest on the real setup. The scrub burst is reproducible on your end, the slow remote seek is not on demand, so a clean run of the same pattern over the WAN link is the only real verification available.
Released in 6.1.1 (f40b263). No API change, no source change on the consumer side.
Leaving this open for a retest over the real WAN link. The failure mode to watch for is the absence of the App Hang under the same scrub burst; if a seek is genuinely slow it should now surface as a slow seek with a live UI, and a reposition that spends its 8 s budget will close its seekEvents ticket as .stalled rather than .landed, which is the cleanest signal to check for on a synchronized-playback host.
Activity
superuser404notfound commentedon Jul 30, 2026
Confirmed and fixed in #256 (839b64c). Thanks for the report, the two hang stacks plus the seek-burst window from the same period were enough to pin this without a local repro.
One correction to the mechanism, because it changes what the fix has to be.
The report reads the mutex frame as the second seek queuing behind the first. That cannot be what happened:
SoftwarePlaybackHostis@MainActor(SoftwarePlaybackHost.swift:12) and the VOD branch ofseek(to:)had no suspension point between the generation bump anddem.seek(to:), so two host seeks can never overlap. The main actor serialized them.The lock holder was the demux loop.
Demuxer.readPackettakesaccessLockand holds it across the whole ofav_read_frame(Demuxer.swift:992-998), and that loop runs ondemuxQueue, so on a remote source the lock is held for the length of one network read, up toAVIOReader.connStallTimeout(20 s). 4.4 s and 5.2 s sit comfortably inside that. The subtitle side readers are not candidates here, they open their ownDemuxerinstances.The consequence: swapping
seekforseekBoundedwould not have prevented either hang.seekBoundedarms its read deadline afteraccessLock.lock(), on the far side of the wait that actually blocked. The missing deadline is a real second hazard, it is just not the one these two events evidence. The main-actor isolation is.So the fix is both, in that order.
Demuxergained an asyncseekBoundedthat runs on a caller-owned serial queue and reports landed / stalled / superseded; both@MainActorhosts now await it. The supersede predicate is evaluated on that queue immediately before the FFmpeg call, so the burst that triggered this collapses onto its last target instead of paying one lock wait per seek. That covers the client-side half you offered to own.Two things the report did not cover that turned out to be the same defect:
SoftwarePlaybackHost.loadandAudioPlaybackHost.loadran theirstartPositionresume seek the same way, inline on the main actor. That is every resume into a remote source, not just a scrub.AudioPlaybackHost.seekis the same shape without the video half.The two other unbounded callers listed in the report are untouched, and neither is a hang risk:
HLSVideoEngineis@unchecked Sendable, sorebuildHEVCExtradataWithInBandParameterSetsruns on a producer thread, andAetherEngine.swift:2656is already inside aTask.detached.Since the seek is now a real suspension point, two follow-on cases are handled in the same change rather than left to surface later: the time tick is gated while a reposition is in flight, because the synchronizer still carries the pre-seek anchor and would otherwise walk the published position over the target; and both hosts re-check teardown after the await. A reposition that spends its 8 s budget closes the #38 ticket as
.stalledrather than reporting a landing the engine cannot back up.Leaving this open for a retest on the real setup. The scrub burst is reproducible on your end, the slow remote seek is not on demand, so a clean run of the same pattern over the WAN link is the only real verification available.
Merge pull request #256 from superuser404notfound/fix/issue254-off-ma…
chore(release): prep 6.1.1 - off-main demuxer reposition
superuser404notfound commentedon Jul 30, 2026
Released in 6.1.1 (f40b263). No API change, no source change on the consumer side.
Leaving this open for a retest over the real WAN link. The failure mode to watch for is the absence of the App Hang under the same scrub burst; if a seek is genuinely slow it should now surface as a slow seek with a live UI, and a reposition that spends its 8 s budget will close its
seekEventsticket as.stalledrather than.landed, which is the cleanest signal to check for on a synchronized-playback host.fix(seek): run the software/audio host demuxer reposition off the mai…
fix(seek): carry transport intent through a superseded reposition (su…
fix(software): AV1 through dav1d seeks onto the nearest keyframe