Skip to content
Snippets Groups Projects
Commit 2cb57251 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

proxy client: protect resolver

parent 446da4b7
No related branches found
No related tags found
No related merge requests found
...@@ -368,6 +368,7 @@ private: ...@@ -368,6 +368,7 @@ private:
* Note: Each context is used in one thread only * Note: Each context is used in one thread only
*/ */
asio::io_context httpContext_; asio::io_context httpContext_;
mutable std::mutex resolverLock_;
std::shared_ptr<http::Resolver> resolver_; std::shared_ptr<http::Resolver> resolver_;
mutable std::mutex requestLock_; mutable std::mutex requestLock_;
......
...@@ -191,7 +191,10 @@ void ...@@ -191,7 +191,10 @@ void
DhtProxyClient::stop() DhtProxyClient::stop()
{ {
if (not isDestroying_.exchange(true)) { if (not isDestroying_.exchange(true)) {
{
std::lock_guard<std::mutex> l(resolverLock_);
resolver_.reset(); resolver_.reset();
}
cancelAllListeners(); cancelAllListeners();
if (infoState_) if (infoState_)
infoState_->cancel = true; infoState_->cancel = true;
...@@ -468,7 +471,9 @@ DhtProxyClient::handleRefreshPut(const asio::error_code &ec, InfoHash key, Value ...@@ -468,7 +471,9 @@ DhtProxyClient::handleRefreshPut(const asio::error_code &ec, InfoHash key, Value
std::shared_ptr<http::Request> std::shared_ptr<http::Request>
DhtProxyClient::buildRequest(const std::string& target) DhtProxyClient::buildRequest(const std::string& target)
{ {
std::unique_lock<std::mutex> l(resolverLock_);
auto resolver = resolver_; auto resolver = resolver_;
l.unlock();
if (not resolver) if (not resolver)
resolver = std::make_shared<http::Resolver>(httpContext_, proxyUrl_, logger_); resolver = std::make_shared<http::Resolver>(httpContext_, proxyUrl_, logger_);
auto request = target.empty() auto request = target.empty()
...@@ -634,6 +639,7 @@ DhtProxyClient::getProxyInfos() ...@@ -634,6 +639,7 @@ DhtProxyClient::getProxyInfos()
auto resolver = std::make_shared<http::Resolver>(httpContext_, proxyUrl_, logger_); auto resolver = std::make_shared<http::Resolver>(httpContext_, proxyUrl_, logger_);
queryProxyInfo(infoState, resolver, AF_INET); queryProxyInfo(infoState, resolver, AF_INET);
queryProxyInfo(infoState, resolver, AF_INET6); queryProxyInfo(infoState, resolver, AF_INET6);
std::lock_guard<std::mutex> l(resolverLock_);
resolver_ = resolver; resolver_ = resolver;
} }
...@@ -806,7 +812,7 @@ DhtProxyClient::listen(const InfoHash& key, ValueCallback cb, Value::Filter filt ...@@ -806,7 +812,7 @@ DhtProxyClient::listen(const InfoHash& key, ValueCallback cb, Value::Filter filt
std::lock_guard<std::mutex> lock(searchLock_); std::lock_guard<std::mutex> lock(searchLock_);
auto& search = searches_[key]; auto& search = searches_[key];
auto query = std::make_shared<Query>(Select{}, std::move(where)); auto query = std::make_shared<Query>(Select{}, std::move(where));
return search.ops.listen(cb, query, filter, [this, key](Sp<Query>, ValueCallback cb, SyncCallback) -> size_t { return search.ops.listen(cb, query, std::move(filter), [this, key](Sp<Query>, ValueCallback cb, SyncCallback) -> size_t {
// Find search // Find search
auto search = searches_.find(key); auto search = searches_.find(key);
if (search == searches_.end()) { if (search == searches_.end()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment