Skip to content

Stop the subscriber entering an ice restart state on a resume - #1018

Closed
avosa wants to merge 8 commits into
livekit:mainfrom
myzonerocks:fix/subscriber-ice-restart
Closed

avosa wants to merge 8 commits into
livekit:mainfrom
myzonerocks:fix/subscriber-ice-restart

Conversation

@avosa

@avosa avosa commented Sep 14, 2026

Copy link
Copy Markdown

Fixes #1017.

A soft reconnect put the subscriber into an ice restart state, and only setRemoteDescription clears that. The server re-offers the subscriber only when the reconnect moved the participant to another node, so after an ordinary resume the flag stayed set for the life of the transport and every later remote candidate was queued instead of applied. The subscriber could no longer take any path the server proposed.

The subscriber no longer enters that state. The server does not send candidates ahead of the offer that introduces them, so queueing them gains nothing, which is the conclusion reached in livekit/client-sdk-js#2054.

The test forces a soft reconnect and asserts a subscriber candidate still reaches the peer connection afterwards.

@changeset-bot

changeset-bot Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8b38654

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
client-sdk-android Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant

CLAassistant commented Sep 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@avosa
avosa marked this pull request as ready for review September 14, 2026 04:39
devin-ai-integration[bot]

This comment was marked as resolved.

@avosa

avosa commented Sep 14, 2026

Copy link
Copy Markdown
Author

Good catch, that window is real. The hold now goes on in onServerOffer before the coroutine is launched, so candidates wait for the offer they belong to and are flushed when its description lands, and nothing holds them across a resume that stays on the same node. Added a test for the window.

devin-ai-integration[bot]

This comment was marked as resolved.

@avosa

avosa commented Sep 14, 2026

Copy link
Copy Markdown
Author

Fixed, and the read turned up two more paths worth closing.

The hold is now a count rather than a flag, because offer handling runs on a multi threaded scope and two server offers can overlap; a flag let the first one to finish release the hold while the second was still outstanding. Every wait now ends when the attempt to set that description ends, whether it lands, is refused, or answers an offer that has since been superseded, and an ice restart offer that never goes out releases its own.

One deliberate difference from the suggestion: a wait that ends without a description leaves the queued candidates where they are instead of discarding them. A candidate that no longer fits is refused by the connection anyway, while discarding would throw away ones that are still good when the refused description was never going to change the credentials.

devin-ai-integration[bot]

This comment was marked as resolved.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +373 to +375
fun expectRemoteDescription() {
executeRTCIfNotClosed { awaitedOffers++ }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Subscriber candidates lost during re-offers

When a server offer arrives, onServerOffer does not call expectRemoteDescription before scheduling its answer. Candidates received before the new description lands reach the old description and can be rejected, breaking the subscriber's new ICE path.

Learn more

A server offer changes the subscriber's remote ICE description. onServerOffer launches the work that applies it, while onTrickle can process a candidate first. With an existing remote description and no pending offer count, addIceCandidate applies that candidate immediately. The new description cannot replay a candidate the peer connection already rejected.

Example: The subscriber has offer A applied. The server sends offer B followed by B's candidate. The answer coroutine has not applied B when the candidate arrives, so the candidate is sent to the peer connection while A is still current instead of waiting for B.

Recommended fix: Open the subscriber's expectRemoteDescription wait synchronously when onServerOffer receives the offer, before launching answerServerOffer. Expose this operation through Transport if needed so it works with the new abstraction. Keep descriptionSettled closing the wait when the offer succeeds or fails.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@avosa avosa closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subscriber stops applying remote ICE candidates after an ice restart

2 participants