aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-08-07 15:11:19 +0200
committerRiccardo Spagni <ric@spagni.net>2017-08-07 15:11:20 +0200
commit43c6e452fa7ddb6557a0776bfc2ea6d3b1bab818 (patch)
treed5493b6e72a2797145dcb8ec4ebea9a430216cbe /src
parentMerge pull request #2216 (diff)
parentp2p: close connections when exiting (diff)
downloadmonero-43c6e452fa7ddb6557a0776bfc2ea6d3b1bab818.tar.xz
Merge pull request #2219
04ebfbfe p2p: close connections when exiting (moneromooo-monero) 9a10148c p2p: fix thread leak (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/p2p/net_node.inl20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 19120c892..3cd48ccf0 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -444,11 +444,11 @@ namespace nodetool
std::vector<std::vector<std::string>> dns_results;
dns_results.resize(m_seed_nodes_list.size());
- std::list<boost::thread*> dns_threads;
+ std::list<boost::thread> dns_threads;
uint64_t result_index = 0;
for (const std::string& addr_str : m_seed_nodes_list)
{
- boost::thread* th = new boost::thread([=, &dns_results, &addr_str]
+ boost::thread th = boost::thread([=, &dns_results, &addr_str]
{
MDEBUG("dns_threads[" << result_index << "] created for: " << addr_str);
// TODO: care about dnssec avail/valid
@@ -474,19 +474,19 @@ namespace nodetool
dns_results[result_index] = addr_list;
});
- dns_threads.push_back(th);
+ dns_threads.push_back(std::move(th));
++result_index;
}
MDEBUG("dns_threads created, now waiting for completion or timeout of " << CRYPTONOTE_DNS_TIMEOUT_MS << "ms");
boost::chrono::system_clock::time_point deadline = boost::chrono::system_clock::now() + boost::chrono::milliseconds(CRYPTONOTE_DNS_TIMEOUT_MS);
uint64_t i = 0;
- for (boost::thread* th : dns_threads)
+ for (boost::thread& th : dns_threads)
{
- if (! th->try_join_until(deadline))
+ if (! th.try_join_until(deadline))
{
MWARNING("dns_threads[" << i << "] timed out, sending interrupt");
- th->interrupt();
+ th.interrupt();
}
++i;
}
@@ -714,6 +714,14 @@ namespace nodetool
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::send_stop_signal()
{
+ std::list<boost::uuids::uuid> connection_ids;
+ m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt) {
+ connection_ids.push_back(cntxt.m_connection_id);
+ return true;
+ });
+ for (const auto &connection_id: connection_ids)
+ m_net_server.get_config_object().close(connection_id);
+
m_payload_handler.stop();
m_net_server.send_stop_signal();
MDEBUG("[node] Stop signal sent");