Skip to content

feat: Room.restartIce() to move media off a degraded candidate pair - #1241

Open
4lxprime wants to merge 2 commits into
livekit:mainfrom
citadellefr:feat/room-restart-ice
Open

4lxprime wants to merge 2 commits into
livekit:mainfrom
citadellefr:feat/room-restart-ice

Conversation

@4lxprime

Copy link
Copy Markdown

Once UDP is blocked, libwebrtc falls back to a TURN relay over TCP/TLS and stays there after UDP comes back, until something restarts ICE. On a link measured end to end, that path sent 3x less video, froze 5x more often and added about 150 ms of audio latency. An app can see the selected pair in getStats(), but had no public way to restart ICE: Engine, handleReconnect and ClientDisconnectReason are internal.

Room.restartIce() reuses the regular resume path with RR_SWITCH_CANDIDATE, the protocol's reason for this case: an iceRestart offer for the publisher, while the server restarts the subscriber.

The mock peer connection now implements restartIce() as a no-op, which the resume path calls on native platforms.

Once UDP is blocked, libwebrtc falls back to a TURN relay over TCP/TLS and
stays there after UDP comes back, until something restarts ICE. On a link
measured end to end, that path sent 3x less video, froze 5x more often and
added about 150 ms of audio latency. An app can see the selected pair in
getStats(), but had no public way to restart ICE: Engine, handleReconnect
and ClientDisconnectReason are internal.

Room.restartIce() reuses the regular resume path with
RR_SWITCH_CANDIDATE, the protocol's reason for this case: an iceRestart
offer for the publisher, while the server restarts the subscriber.

The mock peer connection now implements restartIce() as a no-op, which
the resume path calls on native platforms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment thread lib/src/core/room.dart
Comment on lines +769 to +772
Future<void> restartIce() => engine.handleReconnect(
ClientDisconnectReason.reconnect,
reconnectReason: lk_models.ReconnectReason.RR_SWITCH_CANDIDATE,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 ICE restart future completes too early

When a connected app awaits restartIce(), it completes before ICE restarts. handleReconnect only schedules a timer, so later failures never reach the caller.

Learn more

The public method returns the future from handleReconnect, which completes after scheduling a retry timer. The timer later invokes attemptReconnect; that method catches reconnect failures and starts further retries without completing the original future. A caller cannot await ICE restart completion or distinguish success from eventual disconnect.

Example: An app calls await room.restartIce() and immediately reads the candidate pair. The await completes before the zero-delay timer even opens a new signaling socket, so the old TCP pair is still selected.

Recommended fix: Give the requested reconnect a completion future tied to the final successful resume or failure, and return that future from Room.restartIce(). Preserve the engine's retry behavior and settle the future on disconnect or disposal.

Devin Review


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

Comment thread lib/src/core/room.dart Resolved

This branch has not been deployed

No deployments
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.

2 participants