fix(voip): snapshot _remoteCandidates to avoid concurrent-modification in onAnswerReceived#2375
Open
nemeCIS6 wants to merge 1 commit into
Open
fix(voip): snapshot _remoteCandidates to avoid concurrent-modification in onAnswerReceived#2375nemeCIS6 wants to merge 1 commit into
nemeCIS6 wants to merge 1 commit into
Conversation
…Received The candidate loops await pc.addCandidate() inside a for-in over _remoteCandidates. During the await, trickle-ICE events mutate the same list (add at onCandidatesReceived, clear on hangup/restart), throwing 'Concurrent modification during iteration' — aborting onAnswerReceived before the remaining candidates are applied, so the caller's media can fail to connect (frozen video on networks that rely on late candidates). Iterate a .toList() snapshot so concurrent add/clear can't break the loop. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
Problem
CallSession.onAnswerReceived(andonNegotiateReceived) apply buffered ICE candidates with:Because the loop
awaits inside afor-inover_remoteCandidates, an incoming trickle-ICE event during the await can mutate the same list —_remoteCandidates.add(...)in the candidate handler, or_remoteCandidates.clear()on hangup/restart. That throws:onAnswerReceivedthen aborts before applying the remaining candidates / sendingselect_answer, leaving the caller's ICE negotiation incomplete. On connections that rely on candidates arriving mid-loop (relay/TURN), the caller's media never fully connects — observed in production as frozen outgoing video. Reproduced live on an Android 16 device the instant the callee answered.Fix
Iterate a snapshot so concurrent
add/clearcan't break the loop:Applied to both candidate-draining loops (
onAnswerReceivedandonNegotiateReceived). No behavior change beyond removing the race — any candidates added during the loop are still buffered in_remoteCandidatesand applied on the next negotiation pass, as before.🤖 Generated with Claude Code