Repository navigation
Ci base #1068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ci base #1068
Changes from all commits
096d5e1
f9ea434
f115ef9
e3e12b2
467e789
9641a5f
767c8a1
8b38654
25b6ce4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| "client-sdk-android": patch | ||
| --- | ||
|
|
||
| Fix the subscriber silently buffering remote ICE candidates after a resume | ||
|
|
||
| A soft reconnect put the subscriber into an ice restart state, but only `setRemoteDescription` | ||
| clears that and the server re-offers the subscriber only when the reconnect moved the participant | ||
| to another node. After an ordinary resume no offer arrives, so the state stayed set for the life of | ||
| the transport and every later remote candidate was queued instead of applied, leaving the | ||
| subscriber unable to adopt any new path the server proposed. | ||
|
|
||
| Candidates now wait on the description they belong to rather than on the reconnect. `onServerOffer` | ||
| says a description is coming before it schedules the work that applies it, so a candidate that | ||
| arrives in between is held rather than tried against the description being replaced. Each wait is | ||
| owned by what answers it, an ice restart offer by its own offer id and a server offer by its own | ||
| turn, and it ends when that attempt ends whether the description lands, is refused, or answers an | ||
| offer that has since been superseded. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,7 +92,16 @@ constructor( | |
| ) ?: throw IllegalStateException("peer connection creation failed?") | ||
| }!! | ||
| private val pendingCandidates = mutableListOf<IceCandidate>() | ||
| private var restartingIce: Boolean = false | ||
|
|
||
| /** | ||
| * The offers whose answers are still owed, by offer id, and how many server offers are still to | ||
| * be applied. Candidates wait while either stands, so one belonging to a description that has | ||
| * not landed is never tried against the description it replaces. Only touched on the RTC thread. | ||
| */ | ||
| private val awaitedAnswers = mutableSetOf<Int>() | ||
| private var awaitedOffers = 0 | ||
|
|
||
| private fun awaitingDescription() = awaitedAnswers.isNotEmpty() || awaitedOffers > 0 | ||
|
|
||
| private var renegotiate = false | ||
|
|
||
|
|
@@ -121,7 +130,7 @@ constructor( | |
|
|
||
| fun addIceCandidate(candidate: IceCandidate) { | ||
| executeRTCIfNotClosed { | ||
| if (peerConnection.remoteDescription != null && !restartingIce) { | ||
| if (peerConnection.remoteDescription != null && !awaitingDescription()) { | ||
| peerConnection.addIceCandidate(candidate) | ||
| } else { | ||
| pendingCandidates.add(candidate) | ||
|
|
@@ -139,16 +148,13 @@ constructor( | |
| val result = launchRTCIfNotClosed { | ||
| val currentOfferId = latestOfferId.get() | ||
| if (sd.type == SessionDescription.Type.ANSWER && currentOfferId > 0 && offerId > 0 && currentOfferId > offerId) { | ||
| // The offer this answers has been superseded, so only that offer's wait ends here; | ||
| // the offer that replaced it keeps its own. | ||
| descriptionSettled(sd, offerId, applied = false) | ||
| return@launchRTCIfNotClosed Either.Right("Old offer, ignoring. Expected: $currentOfferId, actual: $offerId") | ||
| } | ||
| val result = peerConnection.setRemoteDescription(sd) | ||
| if (result is Either.Left) { | ||
| pendingCandidates.forEach { pending -> | ||
| peerConnection.addIceCandidate(pending) | ||
| } | ||
| pendingCandidates.clear() | ||
| restartingIce = false | ||
| } | ||
| descriptionSettled(sd, offerId, applied = result is Either.Left) | ||
| return@launchRTCIfNotClosed result | ||
| } ?: Either.Right("PCT is closed.") | ||
|
|
||
|
|
@@ -184,7 +190,6 @@ constructor( | |
| constraints.findConstraint(MediaConstraintKeys.ICE_RESTART) == MediaConstraintKeys.TRUE | ||
| if (iceRestart) { | ||
| LKLog.d { "restarting ice" } | ||
| restartingIce = true | ||
| } | ||
|
|
||
| if (peerConnection.signalingState() == SignalingState.HAVE_LOCAL_OFFER) { | ||
|
|
@@ -208,10 +213,18 @@ constructor( | |
| // this may skip some ids, but is not an issue. | ||
| offerId = latestOfferId.incrementAndGet() | ||
|
|
||
| // An ice restart mints new local credentials, so candidates wait for the answer | ||
| // that carries the far side's. The wait is owned by this offer id alone. | ||
| if (iceRestart) { | ||
| awaitedAnswers.add(offerId) | ||
| } | ||
|
|
||
| val sdpOffer = when (val outcome = peerConnection.createOffer(constraints)) { | ||
| is Either.Left -> outcome.value | ||
| is Either.Right -> { | ||
| LKLog.d { "error creating offer: ${outcome.value}" } | ||
| // No offer goes out, so the answer it would have waited for is not coming. | ||
| awaitedAnswers.remove(offerId) | ||
| return@launchRTCIfNotClosed | ||
| } | ||
| } | ||
|
|
@@ -352,8 +365,40 @@ constructor( | |
| return sdp | ||
| } | ||
|
|
||
| fun prepareForIceRestart() { | ||
| restartingIce = true | ||
| /** | ||
| * Says a remote description is on its way, so candidates for it wait rather than land against | ||
| * the description it replaces. Called before the work that applies it is scheduled, and | ||
| * answered by the attempt to set that description whether it lands or is refused. | ||
| */ | ||
| fun expectRemoteDescription() { | ||
| executeRTCIfNotClosed { awaitedOffers++ } | ||
| } | ||
|
Comment on lines
+373
to
+375
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Server-offer candidates reach the old description When a server offer precedes a candidate, Learn moreThe signal client delivers offers and trickles through separate callbacks. onServerOffer launches offer handling, leaving a gap before answerServerOffer applies the subscriber description. Nothing calls Example: The server sends an ICE-restart offer followed immediately by a subscriber trickle. The candidate reaches the subscriber before the offer coroutine installs the new SDP; WebRTC rejects it instead of receiving it after installation. Recommended fix: Wire Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| /** | ||
| * Ends the wait this description answers, however it ended: an answer ends the wait its own | ||
| * offer opened and no other, a server offer ends one of the waits opened for them. Only a | ||
| * description that landed takes the candidates held, and only once nothing else is awaited. A | ||
| * wait that ended without one leaves them queued rather than dropping them, since one that no | ||
| * longer fits is refused by the connection anyway and one that still fits would be lost. | ||
| */ | ||
| private fun descriptionSettled(sd: SessionDescription, offerId: Int, applied: Boolean) { | ||
| if (sd.type == SessionDescription.Type.ANSWER) { | ||
| // A legacy answer carries no id to match itself to, so it ends whatever was owed. | ||
| if (offerId > 0) { | ||
| awaitedAnswers.remove(offerId) | ||
| } else { | ||
| awaitedAnswers.clear() | ||
| } | ||
| } else if (awaitedOffers > 0) { | ||
| awaitedOffers-- | ||
| } | ||
| if (!applied || awaitingDescription()) { | ||
| return | ||
| } | ||
| pendingCandidates.forEach { pending -> | ||
| peerConnection.addIceCandidate(pending) | ||
| } | ||
| pendingCandidates.clear() | ||
| } | ||
|
|
||
| fun isClosed() = isClosed.get() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Superseded restart permanently holds candidates
When a second ICE restart replaces an unanswered first offer,
awaitedAnswersretains both offer IDs. The replacement's answer removes only its ID, leaving later candidates queued indefinitely.Learn more
createAndSendOffer permits a second ICE restart while signaling is
HAVE_LOCAL_OFFER: it applies the current remote description and creates a new offer. Each restart inserts its ID inawaitedAnswers, but descriptionSettled removes only the answered ID. The first offer was superseded, so its answer need never arrive. Its leftover ID makesawaitingDescription()true indefinitely and prevents all subsequent subscriber/publisher candidates on that transport from being added.Example: Restart offer 7 remains unanswered when another reconnect triggers restart offer 8. Answer 8 arrives, but 7 remains in the set; every later publisher trickle is queued instead of applied.
Recommended fix: Retire the replaced offer's wait when starting a replacement restart, while preserving the replacement's wait and preventing a late answer to the old ID from releasing it.
Was this helpful? React with 👍 or 👎 to provide feedback.