From 9e65c89cef6ac2af301faf889a75849602c43955 Mon Sep 17 00:00:00 2001 From: patnashev Date: Thu, 1 Apr 2021 17:49:23 +0500 Subject: [PATCH 1/2] Lingering connections fix. --- src/RequestImpl.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/RequestImpl.cpp b/src/RequestImpl.cpp index bbb8895..8b00f5c 100644 --- a/src/RequestImpl.cpp +++ b/src/RequestImpl.cpp @@ -170,6 +170,19 @@ class RequestImpl : public Request { } } + ~RequestImpl() { + if (connection_ && connection_->GetSocket().IsOpen()) { + try { + RESTC_CPP_LOG_TRACE_("~RequestImpl(): " << *connection_ + << " is still open. Closing it to prevent problems with lingering connections."); + connection_->GetSocket().Close(); + connection_.reset(); + } + catch (std::exception& ex) { + RESTC_CPP_LOG_WARN_("~RequestImpl(): Caught exception:" << ex.what()); + } + } + } private: void ValidateReply(const Reply& reply) { @@ -474,10 +487,11 @@ class RequestImpl : public Request { DataReader::ReadConfig cfg; cfg.msReadTimeout = properties_->recvTimeout; + auto reader = DataReader::CreateIoReader(connection_, ctx, cfg); auto reply = ReplyImpl::Create(connection_, ctx, owner_, properties_, request_type_); - reply->StartReceiveFromServer( - DataReader::CreateIoReader(connection_, ctx, cfg)); + connection_.reset(); + reply->StartReceiveFromServer(move(reader)); const auto http_code = reply->GetResponseCode(); if (http_code == http_301 || http_code == http_302) { From 3b45802f40173c0a8ebeda2bc4be4bf8cc22bdb6 Mon Sep 17 00:00:00 2001 From: patnashev Date: Thu, 1 Apr 2021 17:53:25 +0500 Subject: [PATCH 2/2] No forced dyn link. --- include/restc-cpp/logging.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/restc-cpp/logging.h b/include/restc-cpp/logging.h index dfb881e..6672fa9 100644 --- a/include/restc-cpp/logging.h +++ b/include/restc-cpp/logging.h @@ -14,10 +14,6 @@ #ifdef RESTC_CPP_LOG_WITH_BOOST_LOG -#ifndef WIN32 -# define BOOST_LOG_DYN_LINK 1 -#endif - #include #define RESTC_CPP_LOG_ERROR_(msg) BOOST_LOG_TRIVIAL(error) << msg