From 80d195d35eba1d1b12f9efbb86734c33d234ad61 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 30 Nov 2022 17:32:46 +0100 Subject: [PATCH] avoid race condition when restarting ICE --- .../xmpp/jingle/WebRTCWrapper.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java index b5ccf5c41..4bb26be72 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java @@ -415,12 +415,20 @@ public class WebRTCWrapper { } void restartIce() { - executorService.execute(() -> { - final PeerConnection peerConnection = requirePeerConnection(); - setIsReadyToReceiveIceCandidates(false); - peerConnection.restartIce(); - requirePeerConnection().restartIce();} - ); + executorService.execute( + () -> { + final PeerConnection peerConnection; + try { + peerConnection = requirePeerConnection(); + } catch (final PeerConnectionNotInitialized e) { + Log.w( + EXTENDED_LOGGING_TAG, + "PeerConnection vanished before we could execute restart"); + return; + } + setIsReadyToReceiveIceCandidates(false); + peerConnection.restartIce(); + }); } public void setIsReadyToReceiveIceCandidates(final boolean ready) {