Fix ICE connection fallback (#2144)

* Fix ICE connection fallback

Short connection detection relied on iceFailedTimeout, which previously
had been misinterpreted. Since we've reduced iceFailedTimeout, it is
creating false negatives.

We'll instead use PingTimeout since clients are expected to keep the
signal connection active.

* reduce ping interval to align with total ice failure timeout
This commit is contained in:
David Zhao
2023-10-15 14:36:12 -07:00
committed by GitHub
parent abe74a3f50
commit 65934e6486
6 changed files with 20 additions and 31 deletions
+3
View File
@@ -58,6 +58,9 @@ const (
disconnectCleanupDuration = 5 * time.Second
migrationWaitDuration = 3 * time.Second
PingIntervalSeconds = 5
PingTimeoutSeconds = 15
)
type pendingTrackInfo struct {
+2 -2
View File
@@ -852,8 +852,8 @@ func (r *Room) createJoinResponseLocked(participant types.LocalParticipant, iceS
SubscriberPrimary: participant.SubscriberAsPrimary(),
ClientConfiguration: participant.GetClientConfiguration(),
// sane defaults for ping interval & timeout
PingInterval: 10,
PingTimeout: 20,
PingInterval: PingIntervalSeconds,
PingTimeout: PingTimeoutSeconds,
ServerInfo: r.serverInfo,
ServerVersion: r.serverInfo.Version,
ServerRegion: r.serverInfo.Region,
+2 -2
View File
@@ -36,9 +36,9 @@ var (
reconcileInterval = 3 * time.Second
// amount of time to give up if a track or publisher isn't found
// ensuring this is longer than iceFailedTimeout so we are certain the participant won't return
notFoundTimeout = iceFailedTimeout
notFoundTimeout = time.Minute
// amount of time to try otherwise before flagging subscription as failed
subscriptionTimeout = iceFailedTimeout
subscriptionTimeout = iceFailedTimeoutTotal
trackRemoveGracePeriod = time.Second
maxUnsubscribeWait = time.Second
)
+4 -3
View File
@@ -59,9 +59,10 @@ const (
negotiationFailedTimeout = 15 * time.Second
dtlsRetransmissionInterval = 100 * time.Millisecond
iceDisconnectedTimeout = 10 * time.Second // compatible for ice-lite with firefox client
iceFailedTimeout = 5 * time.Second // time between disconnected and failed
iceKeepaliveInterval = 2 * time.Second // pion's default
iceDisconnectedTimeout = 10 * time.Second // compatible for ice-lite with firefox client
iceFailedTimeout = 5 * time.Second // time between disconnected and failed
iceFailedTimeoutTotal = iceFailedTimeout + iceDisconnectedTimeout // total time between connecting and failure
iceKeepaliveInterval = 2 * time.Second // pion's default
minTcpICEConnectTimeout = 5 * time.Second
maxTcpICEConnectTimeout = 12 * time.Second // js-sdk has a default 15s timeout for first connection, let server detect failure earlier before that
+6 -2
View File
@@ -607,7 +607,7 @@ func (t *TransportManager) handleConnectionFailed(isShortLived bool) {
lastSignalSince := time.Since(t.lastSignalAt)
signalValid := t.signalSourceValid.Load()
if lastSignalSince > iceFailedTimeout || !signalValid {
if !t.hasRecentSignalLocked() || !signalValid {
// the failed might cause by network interrupt because signal closed or we have not seen any signal in the time window,
// so don't switch to next candidate type
t.params.Logger.Infow("ignoring prefer candidate check by ICE failure because signal connection interrupted",
@@ -754,7 +754,7 @@ func (t *TransportManager) onMediaLossUpdate(loss uint8) {
if loss >= uint8(255*udpLossFracUnstable/100) {
t.udpLossUnstableCount |= 1
if bits.OnesCount32(t.udpLossUnstableCount) >= udpLossUnstableCountThreshold {
if t.udpRTT > 0 && t.signalingRTT < uint32(float32(t.udpRTT)*1.3) && int(t.signalingRTT) < t.params.TCPFallbackRTTThreshold && time.Since(t.lastSignalAt) < iceFailedTimeout {
if t.udpRTT > 0 && t.signalingRTT < uint32(float32(t.udpRTT)*1.3) && int(t.signalingRTT) < t.params.TCPFallbackRTTThreshold && t.hasRecentSignalLocked() {
t.udpLossUnstableCount = 0
t.lock.Unlock()
@@ -826,3 +826,7 @@ func (t *TransportManager) SetSubscriberAllowPause(allowPause bool) {
func (t *TransportManager) SetSubscriberChannelCapacity(channelCapacity int64) {
t.subscriber.SetChannelCapacityOfStreamAllocator(channelCapacity)
}
func (t *TransportManager) hasRecentSignalLocked() bool {
return time.Since(t.lastSignalAt) < PingTimeoutSeconds*time.Second
}