fix(ios): add thread-safety to HybridVideoPlayerEventEmitter listeners#4860
Open
erank-pixel wants to merge 1 commit into
Open
fix(ios): add thread-safety to HybridVideoPlayerEventEmitter listeners#4860erank-pixel wants to merge 1 commit into
erank-pixel wants to merge 1 commit into
Conversation
The `listeners` array in `HybridVideoPlayerEventEmitter` is accessed from multiple threads without synchronization. Events are emitted from async Swift concurrency contexts (e.g. SourceLoaderActor → HybridVideoPlayer → emitEvent) while listeners may be added or removed from the JS thread, causing EXC_BAD_ACCESS (SIGSEGV) crashes due to concurrent mutation during iteration. This commit: - Protects all reads and writes to `_listeners` with an NSLock - Snapshots the listener array before iterating in `emitEvent` so callbacks execute outside the lock (avoiding deadlocks and keeping the critical section minimal) - Makes the backing store `private` to prevent unprotected external access Made-with: Cursor
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.
Summary
HybridVideoPlayerEventEmitter.listenersis accessed from multiple threads without synchronization:emitEvent) happens from Swift concurrency async contexts — e.g.SourceLoaderActor.load()→HybridVideoPlayer.initializePlayerItem()→onLoadStart()runs on a cooperative thread pool queue.addListener/ subscriptionremoveclosures.This causes EXC_BAD_ACCESS (SIGSEGV) crashes in
_swift_release_deallocwhen the array is mutated during iteration, as Swift's copy-on-write optimization leaves a dangling buffer pointer.Crash stack (abbreviated)
Fix
NSLockemitEventso callbacks execute outside the lock (avoids deadlocks, keeps the critical section minimal)privateto prevent unprotected external accessTest plan
patch-package— crash no longer reproduces