From c6e147ff224e1adc9a498d4a06ad54fff710d704 Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Thu, 16 May 2024 12:00:45 -0700 Subject: Race condition resulted in close causing removal of peer connection while other jobs might be using it. --- indra/llwebrtc/llwebrtc.cpp | 23 +++++++++++------------ indra/llwebrtc/llwebrtc.h | 3 +++ 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'indra/llwebrtc') diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index 97c04ae446..5c71831c65 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -670,24 +670,23 @@ void LLWebRTCPeerConnectionImpl::init(LLWebRTCImpl * webrtc_impl) } void LLWebRTCPeerConnectionImpl::terminate() { - rtc::scoped_refptr connection; - mPeerConnection.swap(connection); - rtc::scoped_refptr dataChannel; - mDataChannel.swap(dataChannel); - rtc::scoped_refptr localStream; - mLocalStream.swap(localStream); - mWebRTCImpl->PostSignalingTask( [=]() { - if (connection) + if (mDataChannel) { - connection->Close(); + mDataChannel->UnregisterObserver(); + mDataChannel->Close(); + mDataChannel = nullptr; } - if (dataChannel) + if (mPeerConnection) + { + mPeerConnection->Close(); + mPeerConnection = nullptr; + } + for (auto &observer : mSignalingObserverList) { - dataChannel->UnregisterObserver(); - dataChannel->Close(); + observer->OnPeerConnectionClosed(); } }); } diff --git a/indra/llwebrtc/llwebrtc.h b/indra/llwebrtc/llwebrtc.h index ac71e0c744..ecbab81538 100644 --- a/indra/llwebrtc/llwebrtc.h +++ b/indra/llwebrtc/llwebrtc.h @@ -212,6 +212,9 @@ class LLWebRTCSignalingObserver // Called when a connection enters a failure state and renegotiation is needed. virtual void OnRenegotiationNeeded() = 0; + // Called when a peer connection has shut down + virtual void OnPeerConnectionClosed() = 0; + // Called when the audio channel has been established and audio // can begin. virtual void OnAudioEstablished(LLWebRTCAudioInterface *audio_interface) = 0; -- cgit v1.2.3 From 2b275d43fb70f396bba4249c34442e7d70a76e19 Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Fri, 17 May 2024 13:27:45 -0700 Subject: Clean up some shutdown code. --- indra/llwebrtc/llwebrtc.cpp | 35 ++++++++++++++++++++++------------- indra/llwebrtc/llwebrtc_impl.h | 2 -- 2 files changed, 22 insertions(+), 15 deletions(-) (limited to 'indra/llwebrtc') diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index 5c71831c65..c72841e9e5 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -627,7 +627,6 @@ void LLWebRTCImpl::freePeerConnection(LLWebRTCPeerConnectionInterface* peer_conn std::find(mPeerConnections.begin(), mPeerConnections.end(), peer_connection); if (it != mPeerConnections.end()) { - (*it)->terminate(); mPeerConnections.erase(it); } if (mPeerConnections.empty()) @@ -645,7 +644,6 @@ void LLWebRTCImpl::freePeerConnection(LLWebRTCPeerConnectionInterface* peer_conn LLWebRTCPeerConnectionImpl::LLWebRTCPeerConnectionImpl() : mWebRTCImpl(nullptr), - mClosing(false), mPeerConnection(nullptr), mMute(false), mAnswerReceived(false) @@ -673,20 +671,32 @@ void LLWebRTCPeerConnectionImpl::terminate() mWebRTCImpl->PostSignalingTask( [=]() { - if (mDataChannel) - { - mDataChannel->UnregisterObserver(); - mDataChannel->Close(); - mDataChannel = nullptr; - } if (mPeerConnection) { + if (mDataChannel) + { + { + mDataChannel->Close(); + mDataChannel = nullptr; + } + } + mPeerConnection->Close(); + if (mLocalStream) + { + auto tracks = mLocalStream->GetAudioTracks(); + for (auto& track : tracks) + { + mLocalStream->RemoveTrack(track); + } + mLocalStream = nullptr; + } mPeerConnection = nullptr; - } - for (auto &observer : mSignalingObserverList) - { - observer->OnPeerConnectionClosed(); + + for (auto &observer : mSignalingObserverList) + { + observer->OnPeerConnectionClosed(); + } } }); } @@ -810,7 +820,6 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti bool LLWebRTCPeerConnectionImpl::shutdownConnection() { - mClosing = true; terminate(); return true; } diff --git a/indra/llwebrtc/llwebrtc_impl.h b/indra/llwebrtc/llwebrtc_impl.h index 984aaef734..448d36e3ea 100644 --- a/indra/llwebrtc/llwebrtc_impl.h +++ b/indra/llwebrtc/llwebrtc_impl.h @@ -355,8 +355,6 @@ class LLWebRTCPeerConnectionImpl : public LLWebRTCPeerConnectionInterface, LLWebRTCImpl * mWebRTCImpl; - bool mClosing; - rtc::scoped_refptr mPeerConnectionFactory; bool mMute; -- cgit v1.2.3 From ddbd1ab47ea6cd76ed3e6bf32ffaeb73a32b4a97 Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Sun, 19 May 2024 02:30:45 -0700 Subject: More session shutdown cleanup --- indra/llwebrtc/llwebrtc.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'indra/llwebrtc') diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index c72841e9e5..14fb63ec2a 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -280,9 +280,15 @@ void LLWebRTCImpl::terminate() { connection->terminate(); } - mPeerConnections.clear(); + + // connection->terminate() above spawns a number of Signaling thread calls to + // shut down the connection. The following Blocking Call will wait + // until they're done before it's executed, allowing time to clean up. mSignalingThread->BlockingCall([this]() { mPeerConnectionFactory = nullptr; }); + + mPeerConnections.clear(); + mWorkerThread->BlockingCall( [this]() { @@ -652,7 +658,6 @@ LLWebRTCPeerConnectionImpl::LLWebRTCPeerConnectionImpl() : LLWebRTCPeerConnectionImpl::~LLWebRTCPeerConnectionImpl() { - terminate(); mSignalingObserverList.clear(); mDataObserverList.clear(); } -- cgit v1.2.3