From 4b0c6492da18a29c73a8858b999e3c3a679d557b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Tue, 17 Sep 2019 12:26:04 -0400
Subject: [PATCH] jamiaccount: avoid deadlock in case of auth failure

configurationMutex_ is already locked and not recursive, so we
can't relock this mutex nor call removeAccount here. Use the
generic error to detect if the account is correctly added or not.

Change-Id: I3af3800835702dc17e084ca36b147b81c03f8762
Gitlab: #155
---
 src/jamidht/jamiaccount.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp
index 737e0a2d90..a83609d1dd 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -1056,11 +1056,10 @@ JamiAccount::loadAccount(const std::string& archive_password, const std::string&
             }, [this](AccountManager::AuthError error, const std::string& message)
             {
                 JAMI_WARN("Auth error: %d %s", (int)error, message.c_str());
-                {
-                    std::lock_guard<std::mutex> lock(configurationMutex_);
-                    setRegistrationState(RegistrationState::ERROR_GENERIC);
-                }
-                Manager::instance().removeAccount(getAccountID());
+                setRegistrationState(RegistrationState::ERROR_GENERIC);
+                runOnMainThread([w = weak()] {
+                    Manager::instance().removeAccount(w.lock()->getAccountID());
+                });
             }, std::move(callbacks));
         }
     }
-- 
GitLab