Repository navigation
Recovery paths must not read AVPlayer on the main actor (#422) - #425
Merged
Merged
Conversation
…422) AVPlayer's figplayer-backed getters are synchronous XPC round trips to mediaserverd. AVFoundationOffMain has carried that warning since #134, including what it costs ("past the watchdog threshold, a process kill"), but only the 30 s memory probe ever hopped off. The paths that run precisely BECAUSE the media server is not answering read it straight from the main actor. The reporter measured the consequence on macOS: currentTime() from a host's main actor did not return for 13.3 s during a consumer wedge, returning 30 ms after the re-engage watchdog fired, with the app blocked throughout. seek-deadline loop 4 round trips per pass -> one batched seekBufferSnapshot stall nudge / reload currentTime() twice -> renderedPositionMirror VOD shift-publish line avPlayerBufferAhead() -> awaited off-main premature end (#287) 3 witnesses -> one batched reading For the recovery anchors the mirror is not just the non-blocking choice, it is the correct value. recoveryAnchorPosition(currentRendered:) exists to keep the anchor from sitting below the frame on screen (#115), and currentTime() is the clock, which diverges from the rendered frame during exactly the landing these run in (#123). The wedge path was already passing the mirror; the stall watchdog beside it was reading the player. Left synchronous on purpose: the reads inside load() and the seek completion. Both run at a moment where AVPlayer has just answered. Taking the reads out of the main actor also took the logic out with them. bufferedEnd was a @mainactor property wrapped around a blocking round trip, so its rule had no test; contiguousBufferedEnd is pure and now has eight. One of them records a property nobody had written down: ranges are judged against the playhead rather than against the running end, so two adjacent ranges do not chain and the figure understates the buffer. Recorded, not changed, because seekIsWedged reads an understated buffer as starvation and that deserves its own measurement. 2078 tests green. seektest reports the same tallies and the same settleError as before, and a picture-probe run is unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01RbWZLwBVLGM1xUVXa9NeJ1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The 13.3 s main-thread block @rrgomes measured, and the audit it prompted.
The rule that existed but was not applied
AVFoundationOffMainhas carried the reason since #134: these getters are synchronous XPC round trips to mediaserverd, and "on the main actor a momentarily busy media server turns any of them into a fully blocked main thread and, past the watchdog threshold, a process kill". Only the 30 s memory probe used it. The paths that run precisely BECAUSE the server is not answering read the player directly.bufferedEndseekBufferSnapshot, off-maincurrentTime()at the call site and again insiderenderedPositionMirroravPlayerBufferAheadSeconds()The seek-deadline loop is the sharpest of these: it runs while a seek is not landing, which is exactly the state the block was measured in, and it was taking four round trips per pass.
The mirror is also the right value
recoveryAnchorPosition(currentRendered:)exists to keep a recovery anchor from sitting below the frame already on screen (#115).currentTime()is the clock, and the clock diverges from the rendered frame during exactly the landing these paths run in (#123). The wedge path was already passing the mirror; the stall watchdog beside it was reading the player. So this is a correctness fix as much as a threading one.Left alone on purpose
The reads inside
load()and the seek completion. Both run at a moment where AVPlayer has just answered.A property nobody had written down
Taking the reads off the main actor took the logic out with them:
bufferedEndwas a@MainActorproperty wrapped around a blocking round trip, so its rule had no test at all.contiguousBufferedEndis pure now and has eight. One of them records something the old shape hid: ranges are judged against the playhead rather than against the running end, so[100,152]and[152,170]do not chain and the figure understates the buffer. Recorded rather than changed, becauseseekIsWedgedreads an understated buffer as starvation, and that deserves its own measurement.Verification
2078 tests green.
seektestreports the same tallies and the samesettleErroras before the change, and a--picture-proberun is unchanged. The block itself needs a wedged media server and can only be confirmed on the reporting setup.🤖 Generated with Claude Code
https://claude.ai/code/session_01RbWZLwBVLGM1xUVXa9NeJ1