diff --git a/libi2pd_client/ClientContext.cpp b/libi2pd_client/ClientContext.cpp index cbcbdc49..86a0580a 100644 --- a/libi2pd_client/ClientContext.cpp +++ b/libi2pd_client/ClientContext.cpp @@ -170,19 +170,6 @@ namespace client } m_ServerTunnels.clear (); -#ifndef NO_TORRENTS - // start torrents RPC server - for (auto& it: m_TorrentsRPCServers) - it.second->Stop (); - - for (auto& it: m_TorrentsTunnels) - { - LogPrint(eLogInfo, "Clients: Stopping torrents tunnel"); - it.second->Stop (); - } - m_TorrentsTunnels.clear (); -#endif - if (m_SamBridge) { LogPrint(eLogInfo, "Clients: Stopping SAM bridge"); @@ -217,10 +204,26 @@ namespace client m_ClientForwards.clear(); } +#ifndef NO_TORRENTS + // start torrents RPC server + for (auto& it: m_TorrentsRPCServers) + it.second->Stop (); + + for (auto& it: m_TorrentsTunnels) { - // let tunnels finish + LogPrint(eLogInfo, "Clients: Stopping torrents tunnel"); + it.second->Stop (); + } + if (!m_TorrentsTunnels.empty ()) + { + // let torrent tunnels finish LogPrint(eLogInfo, "Clients: Waiting for ", STOP_DESTINATIONS_TIMEOUT, "seconds"); std::this_thread::sleep_for (std::chrono::seconds (STOP_DESTINATIONS_TIMEOUT)); + } + m_TorrentsTunnels.clear (); +#endif + + { // stop destinations LogPrint(eLogInfo, "Clients: Stopping Destinations"); std::lock_guard lock(m_DestinationsMutex); diff --git a/libi2pd_client/ClientContext.h b/libi2pd_client/ClientContext.h index 14b6538d..09003cde 100644 --- a/libi2pd_client/ClientContext.h +++ b/libi2pd_client/ClientContext.h @@ -81,7 +81,7 @@ namespace client const char TORRENTS_TUNNEL_RPC_PATH[] = "rpcpath"; const char TORRENTS_TUNNEL_RPC_ADDRESS[] = "rpcaddress"; - constexpr int STOP_DESTINATIONS_TIMEOUT = 3; // in seconds + constexpr int STOP_DESTINATIONS_TIMEOUT = 8; // in seconds class ClientContext {