fix(SideloadedSubtitle): guard AVSubtitlesLoader state against concurrent mutation - #127
Open
Efka22 wants to merge 1 commit into
Open
fix(SideloadedSubtitle): guard AVSubtitlesLoader state against concurrent mutation#127Efka22 wants to merge 1 commit into
Efka22 wants to merge 1 commit into
Conversation
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.
Problem
Playing a stream with side-loaded text tracks intermittently crashes on iOS with
EXC_BAD_ACCESSinswift_release_dealloc.AVSubtitlesLoader.requestMap(aDictionary) andsubtitles(anArray) are mutated fromdidInterceptPlaylistRequest(type:request:)andinterceptResponse(type:url:data:)—asynccallbacks that AVFoundation invokes concurrently for the master, variant and subtitle playlists. Concurrent mutation corrupts the collections' backing storage and crashes.The unsynchronized
requestMapwas introduced in 11.0.3 (request interception for the user-agent fix); the crash has been observed in the field since.Fix
Serialize all access to each collection through a dedicated
NSLock(subtitlesLock,requestMapLock), applied via lock-guarded computed properties so no call sites change. The two collections are independent caches with no shared invariant, so they take separate locks; no code path holds both at once, so there is no lock-ordering/deadlock hazard.