From 5bd9a4af705226aebd95231854b3eeaab1d193b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Wed, 7 Apr 2021 13:51:02 -0400 Subject: [PATCH] connectionmanager: reschedule requset handling on io pool Possible workaround for issues with "no response from DHT". It can be a blocked mutex, but I can't reproduce, so this is a tentative to improve the behavior and to be sure it's not a locked mutex there. Change-Id: I4c8f152be08f4243ef1654cd36d661989783be0b GitLab: #421 --- src/jamidht/connectionmanager.cpp | 56 +++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/src/jamidht/connectionmanager.cpp b/src/jamidht/connectionmanager.cpp index ba6ced472a..b75fd91365 100644 --- a/src/jamidht/connectionmanager.cpp +++ b/src/jamidht/connectionmanager.cpp @@ -596,26 +596,43 @@ ConnectionManager::Impl::onDhtConnected(const DeviceId& deviceId) return true; } if (req.isAnswer) { - shared->onPeerResponse(req); + JAMI_DBG() << "Received request answer from " << req.from; } else { - // Async certificate checking - shared->account.findCertificate( - req.from, - [w, req = std::move(req)]( - const std::shared_ptr<dht::crypto::Certificate>& cert) mutable { - auto shared = w.lock(); - if (!shared) - return; - dht::InfoHash peer_h; - if (AccountManager::foundPeerDevice(cert, peer_h)) { - shared->onDhtPeerRequest(req, cert); - } else { - JAMI_WARN() - << shared->account << "Rejected untrusted connection request from " - << req.from; - } - }); + JAMI_DBG() << "Received request from " << req.from; } + // Hack: + // Note: This reschedule on the io pool should not be necessary + // however https://git.jami.net/savoirfairelinux/ring-daemon/-/issues/421 + // is a bit clueless and not reproductible in a debug env for now. However, + // the behavior makes me think this callback is blocked (maybe in getInfos()) + // and this must never happen. + dht::ThreadPool::io().run([w, req = std::move(req)] { + auto shared = w.lock(); + if (!shared) + return; + if (req.isAnswer) { + shared->onPeerResponse(req); + } else { + // Async certificate checking + shared->account.findCertificate( + req.from, + [w, req = std::move(req)]( + const std::shared_ptr<dht::crypto::Certificate>& cert) mutable { + auto shared = w.lock(); + if (!shared) + return; + dht::InfoHash peer_h; + if (AccountManager::foundPeerDevice(cert, peer_h)) { + shared->onDhtPeerRequest(req, cert); + } else { + JAMI_WARN() + << shared->account + << "Rejected untrusted connection request from " << req.from; + } + }); + } + }); + return true; }, dht::Value::UserTypeFilter("peer_request")); @@ -843,6 +860,9 @@ ConnectionManager::Impl::onDhtPeerRequest(const PeerConnectionRequest& req, std::lock_guard<std::mutex> lk(infosMtx_); infos_[{req.from, req.id}] = info; } + JAMI_INFO("[Account:%s] accepting connection from %s", + account.getAccountID().c_str(), + deviceId.c_str()); std::unique_lock<std::mutex> lk {info->mutex_}; info->ice_ = Manager::instance() .getIceTransportFactory() -- GitLab