Skip to content

feat(livekit): add retryThroughRelay flag - #24932

Closed
prlanzarin wants to merge 1 commit into
bigbluebutton:v3.0.x-developfrom
prlanzarin:u30/feat/lk-forcerelay
Closed

prlanzarin wants to merge 1 commit into
bigbluebutton:v3.0.x-developfrom
prlanzarin:u30/feat/lk-forcerelay

Conversation

@prlanzarin

Copy link
Copy Markdown
Member

What does this PR do?

  • feat(livekit): add retryThroughRelay flag
    • We're investigating connectivity failures where LK PCs are not opting
      for relay even though ICE ends up failing on regular candidate pairs.
      With LK, we lack a counterpart of bbb-webrtc-sfu's retryThroughRelay
      flag that forces TURN on connection failures - which was designed
      precisely as stopgap for these scenarios.
    • Add public.media.livekit.retryThroughRelay (default false). When the
      flag is on and the initial LK session fails with a ConnectionError,
      retries set iceTransportPolicy='relay' on the RTCConfiguration until
      the first successful connect.
    • Once the room has connected at least once, the flag no longer applies:
      subsequent mid-session reconnections go through normal candidate selection,
      so long-lived sessions do not pay the relay overhead after recovering.
    • The flag does not abide to forced reconnections (i.e. initiated by
      ourselves), nor is it honored if no TURN server is configured.

Closes Issue(s)

None

Motivation

Related #24615

@prlanzarin prlanzarin added this to the Release 3.0 milestone Apr 16, 2026
@coderabbitai

coderabbitai Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new optional boolean LiveKit setting retryThroughRelay (default false) to types, initial values, and app settings, and threads it into the LiveKit room component. The room tracks connection state (hasEverConnectedRef, lastConnectUsedRelayRef) and, when retryThroughRelay is enabled, no prior successful connection exists, an initial connection fails with a ConnectionError, and a TURN server is available, it retries connecting with rtcConfig.iceTransportPolicy = 'relay'.

Sequence Diagram

sequenceDiagram
    participant App as Application Settings
    participant Container as BBBLiveKitRoomContainer
    participant Room as BBBLiveKitRoom
    participant LiveKit as LiveKit API
    participant Error as Error Handler

    App->>Container: Load retryThroughRelay config
    Container->>Room: Pass retryThroughRelay prop
    Room->>LiveKit: Initial connect (default ICE policy)
    LiveKit-->>Room: ConnectionError / failure
    Room->>Error: onError invoked (logs includes hasEverConnected, forceRelay)
    Note over Room: Evaluate:<br/>retryThroughRelay && !hasEverConnected && hasTurnServer && ConnectionError
    alt Conditions met
        Room->>Room: Set rtcConfig.iceTransportPolicy = 'relay' (force relay)
        Room->>LiveKit: Reconnect with relay-only transport
        LiveKit-->>Room: Success or failure
        Room->>Room: Update hasEverConnectedRef / lastConnectUsedRelayRef
    else Conditions not met
        Room->>LiveKit: Standard reconnect flow
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a retryThroughRelay flag to the LiveKit configuration feature.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose, behavior, and motivation for the retryThroughRelay flag additions across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@prlanzarin
prlanzarin marked this pull request as ready for review April 16, 2026 22:51

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
bigbluebutton-html5/private/config/settings.yml (1)

959-961: Optional: expand the comment to capture full semantics.

The comment accurately describes the retry behavior, but a couple of nuances from the PR description are worth documenting for operators: the flag is ignored when no TURN server is configured, does not apply after the first successful connect, and is not applied to client-initiated forced reconnections.

📝 Proposed doc refinement
-      # retryThroughRelay: when the initial LiveKit connection fails, retries
-      # will force TURN/relay until the first successful connect.
+      # retryThroughRelay: when the initial LiveKit connection fails with a
+      # ConnectionError, retries force iceTransportPolicy='relay' (TURN) until
+      # the first successful connect. Has no effect after the room has
+      # connected at least once, is ignored if no TURN server is available,
+      # and does not apply to client-initiated forced reconnections.
       retryThroughRelay: false
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bigbluebutton-html5/private/config/settings.yml` around lines 959 - 961,
Update the inline comment for the retryThroughRelay setting in settings.yml to
document the full semantics: state that retryThroughRelay applies only to
initial LiveKit connection attempts and will force TURN/relay only until the
first successful connect, it is ignored if no TURN server is configured, and it
does not affect client-initiated forced reconnections; reference the
retryThroughRelay setting name so operators can find and understand these
caveats.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@bigbluebutton-html5/private/config/settings.yml`:
- Around line 959-961: Update the inline comment for the retryThroughRelay
setting in settings.yml to document the full semantics: state that
retryThroughRelay applies only to initial LiveKit connection attempts and will
force TURN/relay only until the first successful connect, it is ignored if no
TURN server is configured, and it does not affect client-initiated forced
reconnections; reference the retryThroughRelay setting name so operators can
find and understand these caveats.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7cd51b01-b861-4ea6-9037-10493d6e779b

📥 Commits

Reviewing files that changed from the base of the PR and between 40a4131 and 22f34fc.

📒 Files selected for processing (4)
  • bigbluebutton-html5/imports/ui/Types/meetingClientSettings.ts
  • bigbluebutton-html5/imports/ui/components/livekit/component.tsx
  • bigbluebutton-html5/imports/ui/core/initial-values/meetingClientSettings.ts
  • bigbluebutton-html5/private/config/settings.yml

We're investigating connectivity failures where LK PCs are _not_ opting
for relay even though ICE ends up failing on regular candidate pairs.
With LK, we lack a counterpart of bbb-webrtc-sfu's retryThroughRelay
flag that forces TURN on connection failures - which was designed
precisely as stopgap for these scenarios.

Add public.media.livekit.retryThroughRelay (default false). When the
flag is on and the initial LK session fails with a ConnectionError,
retries set iceTransportPolicy='relay' on the RTCConfiguration until
the first successful connect.

Once the room has connected at least once, the flag no longer applies:
subsequent mid-session reconnections go through normal candidate selection,
so long-lived sessions do not pay the relay overhead after recovering.

The flag does not abide to forced reconnections (i.e. initiated by
ourselves), nor is it honored if no TURN server is configured.
@prlanzarin
prlanzarin force-pushed the u30/feat/lk-forcerelay branch from 22f34fc to cb9d5dc Compare April 17, 2026 01:17
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
bigbluebutton-html5/imports/ui/components/livekit/component.tsx (1)

281-281: Optional: hasTurnServer is a "seen recently" signal, not a liveness signal.

Per useIceServers (bigbluebutton-html5/imports/ui/components/livekit/hooks.ts), hasSeenTurnServer is set from turnServers.length > 0 on the last successful fetch. If credentials have since expired or the TURN host is unreachable, forcing iceTransportPolicy: 'relay' will just fail faster — which is acceptable given the MAX_CONN_ATTEMPTS cap, but worth keeping in mind when diagnosing logs. You may want to consider triggering a refetch() before the relay retry if the cached TTL has elapsed, so stale creds don't silently undermine the mitigation.

No change required; flagging as a nit since this is a diagnostic/recovery path.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bigbluebutton-html5/imports/ui/components/livekit/component.tsx` at line 281,
The current relay-retry logic uses hasTurnServer (from useIceServers /
hasSeenTurnServer) which is a "seen recently" signal and may be stale; update
the retry path in the component that sets iceTransportPolicy: 'relay' to first
call the hook's refetch() (useIceServers.refetch()) when the cached TTL has
likely elapsed before forcing relay, so you refresh TURN credentials and avoid
failing fast on expired/unreachable TURN; reference useIceServers,
hasSeenTurnServer / hasTurnServer, refetch(), iceTransportPolicy: 'relay', and
MAX_CONN_ATTEMPTS when implementing this check.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@bigbluebutton-html5/imports/ui/components/livekit/component.tsx`:
- Line 281: The current relay-retry logic uses hasTurnServer (from useIceServers
/ hasSeenTurnServer) which is a "seen recently" signal and may be stale; update
the retry path in the component that sets iceTransportPolicy: 'relay' to first
call the hook's refetch() (useIceServers.refetch()) when the cached TTL has
likely elapsed before forcing relay, so you refresh TURN credentials and avoid
failing fast on expired/unreachable TURN; reference useIceServers,
hasSeenTurnServer / hasTurnServer, refetch(), iceTransportPolicy: 'relay', and
MAX_CONN_ATTEMPTS when implementing this check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5aa59624-7231-47fb-a131-df6d9d4e5efa

📥 Commits

Reviewing files that changed from the base of the PR and between 22f34fc and cb9d5dc.

📒 Files selected for processing (4)
  • bigbluebutton-html5/imports/ui/Types/meetingClientSettings.ts
  • bigbluebutton-html5/imports/ui/components/livekit/component.tsx
  • bigbluebutton-html5/imports/ui/core/initial-values/meetingClientSettings.ts
  • bigbluebutton-html5/private/config/settings.yml
🚧 Files skipped from review as they are similar to previous changes (2)
  • bigbluebutton-html5/imports/ui/Types/meetingClientSettings.ts
  • bigbluebutton-html5/private/config/settings.yml

@github-actions

Copy link
Copy Markdown

✅ Automated tests have passed!

@github-actions

Copy link
Copy Markdown

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant