fix: hold signal messages until the ReconnectResponse goes out (#4827)

* fix: hold signal messages until the ReconnectResponse goes out

Clients take the ReconnectResponse as the first message on a resumed or
migrated in signal connection, anything ahead of it is dropped. Hold
messages back until it has been written.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix: keep queued participant updates on a path that always flushes

Queue only while the participant is not ready, that queue is always
drained by the join or reconnect response. Log a dropped SDP, it leaves
the negotiation waiting until the state machine recovers it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix: flush queued updates whenever the connection opens

Queue participant updates while the handshake is pending again, and give
the signaller a hook that fires when the connection opens, on an explicit
open and on the handshake window expiring, so the queue always drains.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix: drive the handshake window off a timer and read the gate atomically

The window ran only when something asked whether the handshake was
pending, so a connection with nothing else to send held its queue.
Reading the gate under the lock the flush takes closes the race where an
update queued just after a flush.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix: ignore a handshake timeout from a wait that has ended

Stop cannot cancel a timeout that is already running, so tag each wait
and let a timeout act only on its own. Count opens atomically in the
test, the timer fires on its own goroutine.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Raja Subramanian
2026-09-01 13:59:04 +05:30
committed by GitHub
co-authored by Claude Opus 5
parent 60e08cb19f
commit 0aae7a4894
8 changed files with 532 additions and 20 deletions
+10 -4
View File
@@ -261,6 +261,10 @@ type ParticipantImpl struct {
state atomic.Value // livekit.ParticipantInfo_State
disconnected chan struct{}
// a migrating in participant resumes on a reconnect response, the client takes it
// only as the first message on the resumed signal connection
reconnectResponseSent atomic.Bool
grants atomic.Pointer[auth.ClaimGrants]
isPublisher atomic.Bool
@@ -612,9 +616,10 @@ func (p *ParticipantImpl) IsReady() bool {
state := p.State()
// when migrating, there is no JoinResponse, state transitions from JOINING -> ACTIVE -> DISCONNECTED
// so JOINING is considered ready.
// so JOINING is considered ready. The ReconnectResponse takes the place of the JoinResponse
// as the message the resumed signal connection opens with, so readiness waits for it.
if p.params.Migration {
return state != livekit.ParticipantInfo_DISCONNECTED
return state != livekit.ParticipantInfo_DISCONNECTED && p.reconnectResponseSent.Load()
}
// when not migrating, there is a JoinResponse, state transitions from JOINING -> JOINED -> ACTIVE -> DISCONNECTED
@@ -2071,8 +2076,9 @@ func (p *ParticipantImpl) setupSignalling() {
Participant: p,
})
p.signaller = signalling.NewSignallerAsync(signalling.SignallerAsyncParams{
Logger: p.params.Logger,
Participant: p,
Logger: p.params.Logger,
Participant: p,
OnHandshakeOpened: p.flushQueuedUpdates,
})
}