fix(engine): delay session close teardown 2s

This commit is contained in:
zarazaex69
2026-05-16 00:09:41 +03:00
parent 4db4007985
commit 0676fc2e47
2 changed files with 14 additions and 1 deletions

View File

@@ -197,8 +197,13 @@ func (s *Session) Close() error {
if !alreadyClosing {
leaveUID := uuid.New().String()
leaveAck := s.registerAckWaiter(leaveUID)
// 2s matches our jitsi tear-down budget. The reason is the same:
// without giving the server time to register the leave, a
// back-to-back reconnection from the same client collides with a
// still-alive ghost participant on the SFU side and inherits
// stale media-flow state.
if s.sendLeave(leaveUID) {
_ = s.waitForAck(leaveUID, leaveAck, 1500*time.Millisecond)
_ = s.waitForAck(leaveUID, leaveAck, 2*time.Second)
} else {
s.removeAckWaiter(leaveUID)
}

View File

@@ -188,6 +188,14 @@ func (s *Session) Close() error {
if s.room != nil {
s.unpublishLocalTracks()
s.room.Disconnect()
// LiveKit's Disconnect() returns once the local SDK state
// is torn down, not when the server has actually evicted
// the participant. Without giving the signalling channel
// time to flush the LEAVE_REQUEST and the server to act on
// it, a back-to-back reconnect from the same identity in
// the same room sees a still-alive ghost participant on
// the SFU and inherits stale publication state.
time.Sleep(2 * time.Second)
}
close(s.sendQueue)
s.wg.Wait()