From 0f57615ea35a4cd82e8b1f69b0c4b4a12f636c67 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 21 Aug 2013 15:55:24 +0000 Subject: [PATCH] attempt at fixing shut-down hang --- include/libtorrent/aux_/session_impl.hpp | 6 ++++++ src/session_impl.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 499a0fc01..6896fb23f 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -737,6 +737,12 @@ namespace libtorrent // object. It is the complete list of all connected // peers. connection_map m_connections; + + // this list holds incoming connections while they + // are performing SSL handshake. When we shut down + // the session, all of these are disconnected, otherwise + // they would linger and stall or hang session shutdown + std::set > m_incoming_sockets; // filters incoming connections ip_filter m_ip_filter; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index f59d084cf..78d2586de 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1811,6 +1811,13 @@ namespace aux { m_timer.cancel(ec); m_lsd_announce_timer.cancel(ec); + for (std::set >::iterator i = m_incoming_sockets.begin() + , end(m_incoming_sockets.end()); i != end; ++i) + { + (*i)->close(); + } + m_incoming_sockets.clear(); + // close the listen sockets for (std::list::iterator i = m_listen_sockets.begin() , end(m_listen_sockets.end()); i != end; ++i) @@ -2710,6 +2717,7 @@ retry: #endif s->get >()->async_accept_handshake( boost::bind(&session_impl::ssl_handshake, this, _1, s)); + m_incoming_sockets.insert(s); } else #endif @@ -2731,6 +2739,8 @@ retry: #if defined TORRENT_ASIO_DEBUGGING complete_async("session_impl::ssl_handshake"); #endif + m_incoming_sockets.erase(s); + error_code e; tcp::endpoint endp = s->remote_endpoint(e); if (e) return;