diff --git a/include/opendht/http.h b/include/opendht/http.h index a31c8aeeaa8f3180a74134357a6b49cbba0e293f..469a86100ad2c6c7866244dce9a301264d90f0a4 100644 --- a/include/opendht/http.h +++ b/include/opendht/http.h @@ -294,6 +294,7 @@ private: Response response_ {}; std::string request_; std::atomic<bool> message_complete_ {false}; + std::atomic<bool> finishing_ {false}; std::unique_ptr<http_parser> parser_; std::unique_ptr<http_parser_settings> parser_s_; diff --git a/src/http.cpp b/src/http.cpp index 833d98acecc08dab552eb282ddc0066ba5f58515..2b8290ffc96bc9744b79659be7ef11f5751a7048 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -53,7 +53,6 @@ Connection::~Connection() if (is_open()){ #ifdef OPENDHT_PROXY_OPENSSL get_socket().cancel(); - get_socket().shutdown(asio::ip::tcp::socket::shutdown_both); #endif get_socket().close(); } @@ -682,10 +681,15 @@ Request::post() void Request::terminate(const asio::error_code& ec) { + if (finishing_.load()) + return; + if (ec != asio::error::eof and ec != asio::error::operation_aborted) if (logger_) logger_->e("[http:request:%i] end with error: %s", id_, ec.message().c_str()); + finishing_.store(true); + // close the connection cancelling the scheduled socket operations on the io_context conn_.reset(); // reset the http_parser holding the data pointer to the user callbacks