From 610f3b165bd783f87249fc6a52b4706fdfa6e97a Mon Sep 17 00:00:00 2001 From: prlanzarin <4529051+prlanzarin@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:42:37 -0300 Subject: [PATCH] fix(bbb-html5): crash when stopping WebRTC peers There's a race condition that may cause a client crash whenever a connectionstatechange callback is cleaned up in a peer without a valid peer connection present in our custom RTCPeerConnection wrapper. Check for peerConnection availability in the WebRtcPeer wrapper before trying to clean up its connectionstatechange callback. --- .../imports/ui/services/bbb-webrtc-sfu/sfu-base-broker.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bigbluebutton-html5/imports/ui/services/bbb-webrtc-sfu/sfu-base-broker.js b/bigbluebutton-html5/imports/ui/services/bbb-webrtc-sfu/sfu-base-broker.js index 0cacec5729..3e34314de2 100644 --- a/bigbluebutton-html5/imports/ui/services/bbb-webrtc-sfu/sfu-base-broker.js +++ b/bigbluebutton-html5/imports/ui/services/bbb-webrtc-sfu/sfu-base-broker.js @@ -283,7 +283,9 @@ class BaseBroker { } if (connectionState === 'failed' || connectionState === 'closed') { - this.webRtcPeer.peerConnection.onconnectionstatechange = null; + if (this.webRtcPeer?.peerConnection) { + this.webRtcPeer.peerConnection.onconnectionstatechange = null; + } // 1307: "ICE_STATE_FAILED", const error = BaseBroker.assembleError(1307); this.onerror(error); @@ -343,7 +345,7 @@ class BaseBroker { this.onerror = function(){}; window.removeEventListener('beforeunload', this.onbeforeunload); - if (this.webRtcPeer) { + if (this.webRtcPeer?.peerConnection) { this.webRtcPeer.peerConnection.onconnectionstatechange = null; }