Avoid unnecessary thread switching in audio cleanup and frame cryptor setup to prevent WebRTC deadlocks#197
Merged
hiroshihorie merged 5 commits intowebrtc-sdk:m137_releasefrom Sep 25, 2025
Conversation
…leanup to prevent WebRTC deadlocks.
…nto m137_release
…nto m137_release
Member
|
Thank you @brainwith for the PR, I will take a better look in the following days.
|
Contributor
Author
@hiroshihorie Yes, I’ve actually hit deadlocks with the audio renderer dealloc. The scenario is roughly:
Stack observation:
That’s why this patch removes the unnecessary thread switch — to avoid this contention. |
hiroshihorie
approved these changes
Sep 25, 2025
cloudwebrtc
pushed a commit
that referenced
this pull request
Feb 2, 2026
… setup to prevent WebRTC deadlocks (#197) ## Description This PR makes two small but important changes to improve thread safety and reduce deadlock risk in the iOS bindings: ### 1. RTCAudioTrack.mm - Remove the explicit [self removeAllRenderers]. - Instead, iterate _adapters and remove each sink from the native audio track without switching threads, aligning the behavior with RTCVideoTrack.mm. - This simplifies teardown and avoids extra synchronization points. ### 2.RTCFrameCryptor.mm - Remove factory.signalingThread->BlockingCall around nativeRtpReceiver->SetDepacketizerToDecoderFrameTransformer(...). - The native call path already runs on the worker thread, so performing a BlockingCall from the signaling thread introduces an unnecessary signaling → worker hop that can increase deadlock risk in tight teardown/configuration sequences. ## Problem Solved - Redundant signaling → worker thread switching during audio renderer cleanup and frame-cryptor configuration could contribute to deadlocks under timing-sensitive conditions (e.g., track teardown overlapping with transformer setup). - By eliminating that extra hop, we reduce contention between signaling and worker threads without changing observable behavior. ## Impact - Lower likelihood of hangs/deadlocks on teardown/configuration paths. - Implementation now matches RTCVideoTrack.mm for audio cleanup. - No public API changes. --------- Co-authored-by: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com>
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.
Description
This PR makes two small but important changes to improve thread safety and reduce deadlock risk in the iOS bindings:
1. RTCAudioTrack.mm
2.RTCFrameCryptor.mm
Problem Solved
Impact