From c8c2bea247fe79a3e1d5527760e5f25152d67626 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 11 Nov 2019 14:44:56 -0500
Subject: [PATCH] sipcall: reschedule startAllMedias on main thread to avoid
 deadlock

im::sendSipMessage is locking dialog when callMutex_ is locked, but
handleEvents can lock dialog then callMutex_ in startAllMedias. This
will give a deadlock, so startAllMedias should be rescheduled

Change-Id: I3d1b0b9a981419840f19bfe1832b70503713fe72
Gitlab: #175
---
 src/sip/sipcall.cpp | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp
index 44f638e44b..b83186727e 100644
--- a/src/sip/sipcall.cpp
+++ b/src/sip/sipcall.cpp
@@ -1091,22 +1091,21 @@ void
 SIPCall::onMediaUpdate()
 {
     JAMI_WARN("[call:%s] medias changed", getCallId().c_str());
-
-    // If ICE is not used, start medias now
-    auto rem_ice_attrs = sdp_->getIceAttributes();
-    if (rem_ice_attrs.ufrag.empty() or rem_ice_attrs.pwd.empty()) {
-        JAMI_WARN("[call:%s] no remote ICE for medias", getCallId().c_str());
-        stopAllMedia();
-        startAllMedia();
-        return;
-    }
-
     // Main call (no subcalls) must wait for ICE now, the rest of code needs to access
     // to a negotiated transport.
     runOnMainThread([w = weak()] {
-        if (auto this_ = w.lock())
+        if (auto this_ = w.lock()) {
+            // If ICE is not used, start medias now
+            auto rem_ice_attrs = this_->sdp_->getIceAttributes();
+            if (rem_ice_attrs.ufrag.empty() or rem_ice_attrs.pwd.empty()) {
+                JAMI_WARN("[call:%s] no remote ICE for medias", this_->getCallId().c_str());
+                this_->stopAllMedia();
+                this_->startAllMedia();
+                return;
+            }
             if (not this_->isSubcall())
                 this_->waitForIceAndStartMedia();
+        }
     });
 }
 
-- 
GitLab