From 9d8ee5a3190ad6001bb22365e866346059a8c168 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sat, 26 Sep 2026 00:08:42 +0530 Subject: [PATCH] Report disconnected for older disconnected participants. (#4910) There are reports of disconnected participant update missing - https://github.com/livekit/client-sdk-js/pull/2096. That results in clients retaining disconnected participant(s) in its roster. Two changes 1. Look for participant disconnects a little farther back than last signal time as client app might have lost visibility earlier. 2. Look at all participants within the relaxed window above. The update cache is LRU. So, in theory can stop when an entry is before the time threshold above. But, theoretically it is possible that `updatedAt` time and LRU queuing time can flip ordering although very unlikely. I think we should do one of the following to make it more robust, but both require client side changes 1. Send full participant list in `ReconnectResponse`. Clients can use that to drop participants not in the list. 2. Add a sequence number to all signal responses (maybe signal requests as well) and have client send up the last response it saw in `SyncState` message. Server can then replay all the messages after that. This also requires a message cache on server side. --- pkg/rtc/participant_signal.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/rtc/participant_signal.go b/pkg/rtc/participant_signal.go index 57f03f30..e32a739b 100644 --- a/pkg/rtc/participant_signal.go +++ b/pkg/rtc/participant_signal.go @@ -243,15 +243,20 @@ func (p *ParticipantImpl) flushQueuedUpdates() { } func (p *ParticipantImpl) sendDisconnectUpdatesForReconnect() error { - lastSignalAt := p.TransportManager.LastSeenSignalAt() + // look back a little more than last signal receive time as WebSocket close + // on client side might have flushed messages and client application may have + // lost connectivity earlier. + lastSignalAt := p.TransportManager.LastSeenSignalAt().Add(-3 * time.Second) var disconnectedParticipants []*livekit.ParticipantInfo p.updateLock.Lock() keys := p.updateCache.Keys() for i := len(keys) - 1; i >= 0; i-- { if info, ok := p.updateCache.Get(keys[i]); ok { if info.updatedAt.Before(lastSignalAt) { - break - } else if info.state == livekit.ParticipantInfo_DISCONNECTED { + continue + } + + if info.state == livekit.ParticipantInfo_DISCONNECTED { disconnectedParticipants = append(disconnectedParticipants, &livekit.ParticipantInfo{ Sid: string(keys[i]), Identity: string(info.identity),