Repository navigation
fix: decide the reconnect mode after the connectivity wait, not before it - #1320
Open
xianshijing-lk wants to merge 1 commit into
Open
xianshijing-lk wants to merge 1 commit into
xianshijing-lk wants to merge 1 commit into
Conversation
xianshijing-lk
requested review from
changt,
cloudwebrtc and
hiroshihorie
as code owners
November 26, 2026 01:04
|
This PR bumps
|
…e it `attemptReconnect` captured `fullReconnectOnNext` up front and only then parked in the connectivity wait, which runs for up to ten connection timeouts. The mode it acted on was therefore a snapshot of state taken before an unbounded wait on that very state. The case that matters: ICE giving up partway through an outage calls `handleReconnect` with `peerConnectionFailed`, which sets `fullReconnectOnNext`. The attempt coming out of the wait had already consumed the flag, so it sent a resume anyway and honored the escalation only on the attempt after it. Move the mode decision below the wait so that request takes effect on the attempt that follows it. Nothing here infers a lost session from the transport's state. `resumeConnection` is built for a peer that is not connected — it sends an ICE restart and waits for the peer to come back — so a transport that went away with the network is still resumable. Escalating on that would trade a recoverable session for a certain loss, because `restartConnection` resets `_reliableDataSequence` and clears `_reliableMessageBuffer`, discarding exactly the packets a resume replays from `lastMessageSeq`. A terminally gone transport already reports itself through `peerConnectionFailed`, which is escalated and now applies to this attempt. `SignalClient.debugNetworkIsAvailable` is a test seam: `networkIsAvailable()` returns true unconditionally under `lkPlatformIsTest()`, which left the whole offline branch unreachable from the unit tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
xianshijing-lk
force-pushed
the
sxian/fix-reconnect-mode-after-connectivity-wait
branch
from
November 26, 2026 01:30
1dd0d78 to
730da13
Compare
This branch has not been deployed
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.
Problem
attemptReconnectcapturedfullReconnectOnNextup front, and only then parked in the connectivity wait:The mode it acts on is a snapshot of state taken before an unbounded wait on that very state.
The case that matters: ICE giving up partway through an outage calls
handleReconnect(peerConnectionFailed), which setsfullReconnectOnNext = true. The attempt coming out of the wait has already consumed the flag, so it sends a resume anyway and honors the escalation only on the attempt after it — one doomed round trip, and the server'scant_migraterejection, before recovery.Fix
Move the mode decision below the wait, so a request raised during the wait takes effect on the attempt that follows it.
Nothing here infers a lost session from the transport's state, deliberately.
resumeConnectionis built for a peer that is not connected — it sendscreateAndSendOffer(iceRestart: true), setssubscriber.restartingIce, and waits for the peer to come back. A transport that went away with the network is therefore still resumable, and escalating on it would trade a recoverable session for a certain loss:restartConnectionresets_reliableDataSequenceand clears_reliableMessageBuffer, discarding exactly the packets a resume replays via_resendReliableMessagesForResume(lastMessageSeq).A terminally gone transport already reports itself through
peerConnectionFailed, whichhandleReconnectescalates — and which now applies to the current attempt rather than the next one.Scope
No change to retry/backoff policy, and no elapsed-time rule. Whether a resume budget should replace Flutter's current escalation conditions is a separate question that needs production measurement.
This SDK does not have the Swift bug fixed in livekit/client-sdk-swift#1244 — it consumes a single flag per attempt rather than seeding one per episode, so a
RECONNECTleave is already honored.Test seam
SignalClient.debugNetworkIsAvailable(@visibleForTesting) is new.networkIsAvailable()returnstrueunconditionally underlkPlatformIsTest(), which left the entire offline branch unreachable from the unit tests — there was no way to exercise this code path at all.Tests
test/core/reconnect_after_connectivity_wait_test.dart, verified againstorigin/main:mainreconnect=1disconnectedacross the waitFull suite: 683 tests pass.
dart analyze lib testclean,dart format --line-length 120clean.🤖 Generated with Claude Code