From 476d0bca4f7a11f55ad3a9cf3bf0248f4d6fead9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Sun, 1 Dec 2019 14:52:42 -0500 Subject: [PATCH] proxy client: lock while canceling requests --- include/opendht/dht_proxy_client.h | 4 ---- src/dht_proxy_client.cpp | 17 +++++++---------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/opendht/dht_proxy_client.h b/include/opendht/dht_proxy_client.h index 6384f577..3afa8af6 100644 --- a/include/opendht/dht_proxy_client.h +++ b/include/opendht/dht_proxy_client.h @@ -319,10 +319,6 @@ private: * cancel all Listeners */ void cancelAllListeners(); - /** - * cancel all Operations - */ - void cancelAllOperations(); std::atomic_bool isDestroying_ {false}; diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index 32dad3e0..cd9a14af 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -154,12 +154,16 @@ DhtProxyClient::stop() { isDestroying_ = true; resolver_.reset(); - cancelAllOperations(); cancelAllListeners(); if (infoState_) infoState_->cancel = true; - for (auto& request : requests_) - request.second->cancel(); + { + std::lock_guard<std::mutex> lock(requestLock_); + for (auto& request : requests_) + request.second->cancel(); + } + if (not httpContext_.stopped()) + httpContext_.stop(); if (httpClientThread_.joinable()) httpClientThread_.join(); requests_.clear(); @@ -183,13 +187,6 @@ DhtProxyClient::getLocalById(const InfoHash& k, Value::Id id) const { return s->second.ops.get(id); } -void -DhtProxyClient::cancelAllOperations() -{ - if (!httpContext_.stopped()) - httpContext_.stop(); -} - void DhtProxyClient::cancelAllListeners() { -- GitLab