From ef8a3833eb481d2174a13c12fa13044a65d8be5f Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Wed, 13 Mar 2024 13:15:50 -0700 Subject: Add increasing random timeout to retries. --- indra/newview/llvoicewebrtc.cpp | 29 +++++++++++++++++++++++++---- indra/newview/llvoicewebrtc.h | 6 ++++++ 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp index 2bb16cb336..d3ea02633f 100644 --- a/indra/newview/llvoicewebrtc.cpp +++ b/indra/newview/llvoicewebrtc.cpp @@ -92,6 +92,7 @@ namespace { // Don't send positional updates more frequently than this: const F32 UPDATE_THROTTLE_SECONDS = 0.1f; + const F32 MAX_RETRY_WAIT_SECONDS = 10.0f; // Cosine of a "trivially" small angle const F32 FOUR_DEGREES = 4.0f * (F_PI / 180.0f); @@ -1988,8 +1989,13 @@ LLVoiceWebRTCConnection::LLVoiceWebRTCConnection(const LLUUID ®ionID, const s mMicGain(0.0), mOutstandingRequests(0), mChannelID(channelID), - mRegionID(regionID) + mRegionID(regionID), + mRetryWaitPeriod(0) { + // retries wait a short period...randomize it so + // all clients don't try to reconnect at once. + mRetryWaitSecs = ((F32) rand() / (RAND_MAX)) + 0.5; + mWebRTCPeerConnectionInterface = llwebrtc::newPeerConnection(); mWebRTCPeerConnectionInterface->setSignalingObserver(this); } @@ -2567,6 +2573,9 @@ bool LLVoiceWebRTCConnection::connectionStateMachine() case VOICE_STATE_SESSION_UP: { + mRetryWaitPeriod = 0; + mRetryWaitSecs = ((F32) rand() / (RAND_MAX)) + 0.5; + // we'll stay here as long as the session remains up. if (mShutDown) { @@ -2576,9 +2585,21 @@ bool LLVoiceWebRTCConnection::connectionStateMachine() } case VOICE_STATE_SESSION_RETRY: - // something went wrong, so notify that the connection has failed. - LLWebRTCVoiceClient::getInstance()->OnConnectionFailure(mChannelID, mRegionID); - setVoiceConnectionState(VOICE_STATE_DISCONNECT); + // only retry ever 'n' seconds + if (mRetryWaitPeriod++ * UPDATE_THROTTLE_SECONDS > mRetryWaitSecs) + { + // something went wrong, so notify that the connection has failed. + LLWebRTCVoiceClient::getInstance()->OnConnectionFailure(mChannelID, mRegionID); + setVoiceConnectionState(VOICE_STATE_DISCONNECT); + mRetryWaitPeriod = 0; + if (mRetryWaitSecs < MAX_RETRY_WAIT_SECONDS) + { + // back off the retry period, and do it by a small random + // bit so all clients don't reconnect at once. + mRetryWaitSecs += ((F32) rand() / (RAND_MAX)) + 0.5; + mRetryWaitPeriod = 0; + } + } break; case VOICE_STATE_DISCONNECT: diff --git a/indra/newview/llvoicewebrtc.h b/indra/newview/llvoicewebrtc.h index 03bbe00162..b26bea27ce 100644 --- a/indra/newview/llvoicewebrtc.h +++ b/indra/newview/llvoicewebrtc.h @@ -694,6 +694,12 @@ class LLVoiceWebRTCConnection : bool mShutDown; S32 mOutstandingRequests; + S32 mRetryWaitPeriod; // number of UPDATE_THROTTLE_SECONDS we've + // waited since our last attempt to connect. + F32 mRetryWaitSecs; // number of seconds to wait before next retry + + + std::vector mIceCandidates; bool mIceCompleted; bool mTrickling; -- cgit v1.2.3