Fix reported issue with room reconnect when wifi reconnects#900
Open
darryncampbell wants to merge 1 commit intomainfrom
Open
Fix reported issue with room reconnect when wifi reconnects#900darryncampbell wants to merge 1 commit intomainfrom
darryncampbell wants to merge 1 commit intomainfrom
Conversation
|
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.
To address issue: https://github.com/fabiogambaaik/livekit-demo-app
Problem
When Wi-Fi is disabled on an Android device with multiple concurrent LiveKit rooms, two issues occur:
PeerConnectionState.DISCONNECTED as transient, so these rooms remain stuck showing CONNECTED despite having no network.
making blocking WebSocket/DNS calls to unreachable servers. By the time Android's NetworkCallback.onAvailable() fires (~10+ seconds later), all engines have active reconnect jobs stuck in blocking joinImpl() calls. The existing engine.reconnect() call from onAvailable hits the reconnectingJob?.isActive guard and
does nothing. The stuck jobs eventually exhaust the 60-second timeout or all 30 retries, and rooms never recover.
Changes
Room.kt — onLost callback: Set Room state to RECONNECTING and post RoomEvent.Reconnecting immediately when Android reports network loss. This ensures all rooms accurately reflect their connectivity status using the OS-level network signal, rather than waiting for ICE state detection that may never fire for some
rooms.
Room.kt — onAvailable callback: Call engine.forceReconnect() instead of engine.reconnect(). The old reconnect() path could never succeed because the engine's own reconnect job was always already active (started by ICE state detection while offline).
Room.kt — reconnect() method: Removed the state == State.RECONNECTING guard. This guard was preventing onAvailable from triggering reconnection for rooms that had already transitioned to RECONNECTING via onEngineReconnecting. With the new forceReconnect() approach from onAvailable, this method is now only used by
other internal callers and the guard is unnecessary (the engine has its own idempotency guard).
RTCEngine.kt — New forceReconnect() method: Cancels any in-progress reconnect job, clears the job reference, sets fullReconnectOnNext = true, and calls reconnect() to start a fresh reconnect loop. This is necessary because:
Why not trigger engine.reconnect() from onLost?
Starting the reconnect loop while offline would waste the retry budget (30 retries, 60s timeout) on a network that's known to be down. The engine could exhaust all retries before network returns, making recovery impossible. The engine already self-starts reconnection via ICE state detection anyway — the fix
addresses the recovery side (onAvailable), not the detection side.