Skip to content

Commit

Permalink
fix(ice-restart): Use an exponential backoff timer for ICE restarts. (#…
Browse files Browse the repository at this point in the history
…2531)

Use an exponential backoff time for initiating ICE restart to prevent loading the prosody.

When a large number of endpoints loose connection to the signaling and media servers because of an ISP failure, these endpoints will try to reconnect at the same time causing a storm of source-remove/source-add events to the signaling servers that can lead to prosody going down otherwise.
  • Loading branch information
jallamsetty1 authored May 21, 2024
1 parent 63a0348 commit 5a14bd4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
40 changes: 25 additions & 15 deletions JitsiConference.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Statistics from './modules/statistics/statistics';
import EventEmitter from './modules/util/EventEmitter';
import { safeSubtract } from './modules/util/MathUtil';
import RandomUtil from './modules/util/RandomUtil';
import { getJitterDelay } from './modules/util/Retry';
import ComponentsVersions from './modules/version/ComponentsVersions';
import VideoSIPGW from './modules/videosipgw/VideoSIPGW';
import * as VideoSIPGWConstants from './modules/videosipgw/VideoSIPGWConstants';
Expand Down Expand Up @@ -325,6 +326,11 @@ export default function JitsiConference(options) {

this._firefoxP2pEnabled = browser.isVersionGreaterThan(109)
&& (this.options.config.testing?.enableFirefoxP2p ?? true);

/**
* Number of times ICE restarts that have been attempted after ICE connectivity with the JVB was lost.
*/
this._iceRestarts = 0;
}

// FIXME convert JitsiConference to ES6 - ASAP !
Expand Down Expand Up @@ -418,24 +424,21 @@ JitsiConference.prototype._init = function(options = {}) {
}
});

// Connection interrupted/restored listeners
this._onIceConnectionInterrupted
= this._onIceConnectionInterrupted.bind(this);
this.room.addListener(
XMPPEvents.CONNECTION_INTERRUPTED, this._onIceConnectionInterrupted);
// ICE Connection interrupted/restored listeners.
this._onIceConnectionEstablished = this._onIceConnectionEstablished.bind(this);
this.room.addListener(XMPPEvents.CONNECTION_ESTABLISHED, this._onIceConnectionEstablished);

this._onIceConnectionRestored = this._onIceConnectionRestored.bind(this);
this.room.addListener(
XMPPEvents.CONNECTION_RESTORED, this._onIceConnectionRestored);
this._onIceConnectionFailed = this._onIceConnectionFailed.bind(this);
this.room.addListener(XMPPEvents.CONNECTION_ICE_FAILED, this._onIceConnectionFailed);

this._onIceConnectionEstablished
= this._onIceConnectionEstablished.bind(this);
this.room.addListener(
XMPPEvents.CONNECTION_ESTABLISHED, this._onIceConnectionEstablished);
this._onIceConnectionInterrupted = this._onIceConnectionInterrupted.bind(this);
this.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED, this._onIceConnectionInterrupted);

this._onIceConnectionRestored = this._onIceConnectionRestored.bind(this);
this.room.addListener(XMPPEvents.CONNECTION_RESTORED, this._onIceConnectionRestored);

this._updateProperties = this._updateProperties.bind(this);
this.room.addListener(XMPPEvents.CONFERENCE_PROPERTIES_CHANGED,
this._updateProperties);
this.room.addListener(XMPPEvents.CONFERENCE_PROPERTIES_CHANGED, this._updateProperties);

this._sendConferenceJoinAnalyticsEvent = this._sendConferenceJoinAnalyticsEvent.bind(this);
this.room.addListener(XMPPEvents.MEETING_ID_SET, this._sendConferenceJoinAnalyticsEvent);
Expand Down Expand Up @@ -2854,8 +2857,15 @@ JitsiConference.prototype._onIceConnectionFailed = function(session) {
reasonDescription: 'ICE FAILED'
});
} else if (session && this.jvbJingleSession === session) {
// Use an exponential backoff timer for ICE restarts.
const jitterDelay = getJitterDelay(this._iceRestarts, 1000 /* min. delay */);

this._delayedIceFailed = new IceFailedHandling(this);
this._delayedIceFailed.start(session);
setTimeout(() => {
logger.error(`triggering ice restart after ${jitterDelay} `);
this._delayedIceFailed.start(session);
this._iceRestarts++;
}, jitterDelay);
}
};

Expand Down
5 changes: 0 additions & 5 deletions JitsiConferenceEventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,6 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
JitsiConferenceEvents.CONFERENCE_FAILED,
JitsiConferenceErrors.GRACEFUL_SHUTDOWN);

chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
jingleSession => {
conference._onIceConnectionFailed(jingleSession);
});

this.chatRoomForwarder.forward(XMPPEvents.MUC_DESTROYED,
JitsiConferenceEvents.CONFERENCE_FAILED,
JitsiConferenceErrors.CONFERENCE_DESTROYED);
Expand Down

0 comments on commit 5a14bd4

Please sign in to comment.