Skip to content

Restart signal pings after a resume - #1328

Merged
hiroshihorie merged 4 commits into
mainfrom
hiroshi/restart-pings-after-resume
Dec 1, 2026
Merged

hiroshihorie merged 4 commits into
mainfrom
hiroshi/restart-pings-after-resume

Conversation

@hiroshihorie

Copy link
Copy Markdown
Member

Problem

SignalClient starts the signal pings and the ping timeout only when a JoinResponse arrives. connect() cleans up the old socket, which cancels both timers. A resume gets a ReconnectResponse and no JoinResponse, so after the first resume no pings are sent and no ping timeout is armed for the rest of the session, until a full reconnect.

What that hurts:

  • A signal socket that goes half open after a resume, while media keeps flowing, is never detected. Examples are a NAT rebinding of the TCP flow, a proxy or load balancer dropping the socket, or a network change on mobile. The peer connection does not fail, so nothing triggers a reconnect. Signal messages in both directions are lost silently, including participant and track updates and token refreshes.
  • The server stops getting pingReq. It does not time out the client for that, but its lastSignalAt goes stale when nothing else is sent for 15 seconds, which turns off its ICE failure candidate fallback and its TCP fallback (pkg/rtc/transportmanager.go in livekit/livekit). The signalling RTT also stops updating on both sides.

Fix

Restart the pings when the ReconnectResponse arrives, with the interval and timeout kept from the JoinResponse. The fields are not cleared by cleanUp(), so they are still set on a resume.

How the other SDKs do it:

  • client-sdk-js starts the ping interval in handleSignalConnected for a join and for a reconnect, with the values cached from the JoinResponse.
  • client-sdk-android restarts the ping job on the first message while reconnecting.
  • rust-sdks starts the signal task again on restart(), with the stored JoinResponse.
  • client-sdk-swift calls _restartPingTimer() on the ReconnectResponse, but cleanUp() clears the cached JoinResponse first, so it has the same gap. That needs its own fix.

Testing

  • New unit test in test/core/signal_client_test.dart: join with a 1 second interval and a 2 second timeout, resume, then check that pings go out on the new socket and that the timeout reports the socket as lost when no pong comes back. It fails on main and passes with the fix.
  • flutter test (all unit tests) and flutter analyze pass locally.
  • Not run against a server. No e2e-flutter scenario covers signal pings yet.

The pings and the ping timeout only started on a JoinResponse. A resume
gets a ReconnectResponse instead, and connect() had already cleared the
timers of the old socket, so after the first resume no pings were sent
and a dead signal socket was never detected for the rest of the session.

Start them again when the ReconnectResponse arrives, with the interval
and timeout kept from the JoinResponse, as client-sdk-js, Android and
Rust do.
@github-actions

Copy link
Copy Markdown
Contributor

This PR bumps

  • livekit_client: patch

@hiroshihorie
hiroshihorie marked this pull request as ready for review December 1, 2026 05:12

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

A join with a ping timeout but a zero interval started a periodic timer
with no period, which sends pings in a tight loop, and with this branch
it would do so again after every resume. Pings now need both values to
be positive, as the Swift SDK requires, and a join without them turns
pings off like a join that omits them.
@hiroshihorie
hiroshihorie merged commit 85d6bfd into main Dec 1, 2026
16 of 17 checks passed
@hiroshihorie
hiroshihorie deleted the hiroshi/restart-pings-after-resume branch December 1, 2026 07:47
hiroshihorie added a commit that referenced this pull request Dec 4, 2026
<!-- verwalter release -->
Merging this PR releases:

## livekit_client `2.14.0` → `2.15.0`

### Minor Changes

- RTCConfiguration.continualGatheringPolicy. Peer connections now gather
ICE candidates continually by default, like the Swift, Android and JS
SDKs, so a network change such as Wi-Fi to cellular produces new
candidates without waiting for an ICE restart. Set
RTCContinualGatheringPolicy.gatherOnce to keep the previous behavior. -
[#1311](#1311)
([@lukasIO](https://github.com/lukasIO))
- LiveKitClient.initialize() now enables enableWARP and zeroPlayoutDelay
by default. Pass false to keep the previous behavior -
[#1321](#1321)
([@cloudwebrtc](https://github.com/cloudwebrtc))
- Data published without reliable: true is no longer retransmitted,
because the maxRetransmits of 0 on the lossy data channel now reaches
the platform -
[#1323](#1323)
([@hiroshihorie](https://github.com/hiroshihorie))
- Single peer connection support -
[#1025](#1025)
([@hiroshihorie](https://github.com/hiroshihorie))

### Patch Changes

- Keep one dependency descriptor extension id across the SDP bundle -
[#1310](#1310)
([@cloudwebrtc](https://github.com/cloudwebrtc))
- disconnect() tears the room down locally after sending the Leave
instead of waiting for the server to echo it, so it no longer stalls 10
s when the echo is lost. A disconnect() call while one is already
tearing down returns at once, so one Leave is sent and one disconnect
reported -
[#1208](#1208)
([@hiroshihorie](https://github.com/hiroshihorie))
- A late close from a signal socket the SDK already replaced no longer
starts another reconnect. In a browser it arrives up to seconds later,
which made a room resume every 2 s after its first reconnect -
[#1211](#1211)
([@hiroshihorie](https://github.com/hiroshihorie))
- Update the Rust core (livekit_ffi) to 0.16.0 -
[#1329](#1329)
([@hiroshihorie](https://github.com/hiroshihorie))
- Mark SDK plumbing members such as `LocalVideoTrack.subscribedCodecs`,
the `prevStats` fields of tracks and the proto conversions of `RpcError`
as `@internal`, so the analyzer warns when an app uses them. -
[#1314](#1314)
([@hiroshihorie](https://github.com/hiroshihorie))
- Offers and answers now carry offer ids, so a late answer to an offer
that an ICE restart or a newer offer replaced is ignored instead of
being applied to the wrong offer -
[#1262](#1262)
([@hiroshihorie](https://github.com/hiroshihorie))
- A track that fails to republish after a full reconnect no longer
leaves the tracks after it unpublished or the room without a
`RoomReconnectedEvent`. The failure is logged, the track is reported
with a `LocalTrackUnpublishedEvent`, and the remaining tracks are
republished -
[#1302](#1302)
([@j-mercker](https://github.com/j-mercker))
- Signal pings and the ping timeout now restart after a resume, so a
signal connection that goes dead after a resume is detected and
recovered instead of going unnoticed for the rest of the session -
[#1328](#1328)
([@hiroshihorie](https://github.com/hiroshihorie))
- Fully reconnect when a resume cannot restart ICE because the pending
offer no longer matches the last answer -
[#1025](#1025)
([@hiroshihorie](https://github.com/hiroshihorie))
- A resume now ends as soon as the server asks for a full reconnect or
the signal connection drops, instead of waiting out a timeout of up to
10 seconds, and a resume the server gave up on is no longer reported as
reconnected before the full reconnect -
[#1322](#1322)
([@hiroshihorie](https://github.com/hiroshihorie))
- A resume now waits until the publisher has finished its ICE restart
before the room reports it reconnected, so reliable data sent right
after a node migration is no longer lost, and a publisher that cannot
reconnect leads to a full reconnect instead of repeated resumes. -
[#1315](#1315)
([@hiroshihorie](https://github.com/hiroshihorie))
- Negotiate Opus NACK on every audio section in single peer connection
mode, including send-only offers created before any subscriptions,
enabling retransmission of lost audio in both publish and subscribe
directions when RED is disabled, such as with end-to-end encryption.
Accept server-offered Opus NACK in dual peer connection subscriber
answers, with fallback if the modified answer is rejected -
[#1025](#1025)
([@hiroshihorie](https://github.com/hiroshihorie))
- Web: a signal connection that fails after it opened no longer throws
an uncaught Future already completed error -
[#1303](#1303)
([@j-mercker](https://github.com/j-mercker))
- Update flutter_webrtc to 1.7.0 and WebRTC-SDK to 150.7871.09, which on
iOS stops the audio engine from starting twice when an audio
interruption ends and lets it start again after a failed audio session
deactivation -
[#1323](#1323)
([@hiroshihorie](https://github.com/hiroshihorie))

Changesets: `continual-gathering-policy.md`,
`dd-extension-bundle-id.md`, `disconnect-completes-on-socket-close.md`,
`enable-warp-zero-playout-by-default.md`,
`ignore-replaced-socket-callbacks.md`, `livekit-ffi-0.16.md`,
`lossy-data-channel-unreliable.md`, `mark-internal-api.md`,
`offer-ids.md`, `republish-all-tracks-after-failure.md`,
`restart-pings-after-resume.md`, `resume-pending-offer.md`,
`resume-stops-on-reconnect-leave.md`, `resume-waits-for-publisher.md`,
`single-pc-opus-nack.md`, `single-pc.md`,
`web-websocket-error-after-open.md`, `webrtc-150-7871-09.md`

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com>
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.

1 participant