From ccd51d289e0e2fb9bdf83a955caff1c5d66820ca Mon Sep 17 00:00:00 2001 From: An Tao Date: Mon, 22 Jun 2020 19:55:24 +0800 Subject: [PATCH] Destroy DNS resolver of HttpClient in the correct thread (#490) --- lib/src/HttpClientImpl.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/src/HttpClientImpl.cc b/lib/src/HttpClientImpl.cc index 7e5c1548..e02ac352 100644 --- a/lib/src/HttpClientImpl.cc +++ b/lib/src/HttpClientImpl.cc @@ -192,6 +192,11 @@ HttpClientImpl::HttpClientImpl(trantor::EventLoop *loop, HttpClientImpl::~HttpClientImpl() { LOG_TRACE << "Deconstruction HttpClient"; + if (resolverPtr_ && !(loop_->isInLoopThread())) + { + // Make sure the resolverPtr_ is destroyed in the correct thread. + loop_->queueInLoop([reolverPtr = resolverPtr_]() {}); + } } void HttpClientImpl::sendRequest(const drogon::HttpRequestPtr &req,