diff options
author | luigi1111 <luigi1111w@gmail.com> | 2021-09-23 22:06:35 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2021-09-23 22:06:35 -0500 |
commit | 237acd120e0da39913bd7b195e2309eff06d639e (patch) | |
tree | ff3f9451fb777ed6b3abdfc4ec7cd37ad086cfbf /src | |
parent | Merge pull request #7886 (diff) | |
parent | Quicker resource cleanup on p2p socks timeout (diff) | |
download | monero-237acd120e0da39913bd7b195e2309eff06d639e.tar.xz |
Merge pull request #7890
2a8a511 Quicker resource cleanup on p2p socks timeout (Lee *!* Clagett)
Diffstat (limited to 'src')
-rw-r--r-- | src/net/socks.h | 7 | ||||
-rw-r--r-- | src/p2p/net_node.cpp | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/net/socks.h b/src/net/socks.h index 739c972ab..506b53195 100644 --- a/src/net/socks.h +++ b/src/net/socks.h @@ -201,6 +201,13 @@ namespace socks std::shared_ptr<client> self_; void operator()(boost::system::error_code error = boost::system::error_code{}); }; + + //! Calls `async_close` on `self` at destruction. NOP if `nullptr`. + struct close_on_exit + { + std::shared_ptr<client> self; + ~close_on_exit() { async_close{std::move(self)}(); } + }; }; template<typename Handler> diff --git a/src/p2p/net_node.cpp b/src/p2p/net_node.cpp index c951db085..d9050200a 100644 --- a/src/p2p/net_node.cpp +++ b/src/p2p/net_node.cpp @@ -342,6 +342,7 @@ namespace nodetool } }; + net::socks::client::close_on_exit close_client{}; boost::unique_future<client_result> socks_result{}; { boost::promise<client_result> socks_promise{}; @@ -350,6 +351,7 @@ namespace nodetool auto client = net::socks::make_connect_client( boost::asio::ip::tcp::socket{service}, net::socks::version::v4a, notify{std::move(socks_promise)} ); + close_client.self = client; if (!start_socks(std::move(client), proxy, remote)) return boost::none; } @@ -371,7 +373,10 @@ namespace nodetool { auto result = socks_result.get(); if (!result.first) + { + close_client.self.reset(); return {std::move(result.second)}; + } MERROR("Failed to make socks connection to " << remote.str() << " (via " << proxy << "): " << result.first.message()); } |