From 0bada79b6bb5ad3e40b7351f340c7dba86cc8e3e Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Mon, 22 Jul 2024 00:16:41 +0200 Subject: [PATCH] Fixed an occasional deadlock on exit with merge mining active --- src/p2pool.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/p2pool.cpp b/src/p2pool.cpp index 1acf1b2b..9f9b356d 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -204,13 +204,14 @@ p2pool::~p2pool() } #endif + std::vector merge_mining_clients; { WriteLock lock(m_mergeMiningClientsLock); + merge_mining_clients.swap(m_mergeMiningClients); + } - for (const IMergeMiningClient* c : m_mergeMiningClients) { - delete c; - } - m_mergeMiningClients.clear(); + for (const IMergeMiningClient* c : merge_mining_clients) { + delete c; } uv_rwlock_destroy(&m_mainchainLock); @@ -534,6 +535,10 @@ void p2pool::handle_chain_main(ChainMain& data, const char* extra) void p2pool::update_aux_data(const hash& chain_id) { + if (m_stopped) { + return; + } + MinerData data; std::vector aux_id; @@ -1026,19 +1031,20 @@ void p2pool::download_block_headers(uint64_t current_height) } } - { - WriteLock lock(m_mergeMiningClientsLock); - - m_mergeMiningClients.clear(); + std::vector merge_mining_clients; - for (const auto& h : m_params->m_mergeMiningHosts) { - IMergeMiningClient* c = IMergeMiningClient::create(this, h.m_host, h.m_wallet); - if (c) { - m_mergeMiningClients.push_back(c); - } + for (const auto& h : m_params->m_mergeMiningHosts) { + IMergeMiningClient* c = IMergeMiningClient::create(this, h.m_host, h.m_wallet); + if (c) { + merge_mining_clients.push_back(c); } } + { + WriteLock lock(m_mergeMiningClientsLock); + m_mergeMiningClients = merge_mining_clients; + } + m_startupFinished = true; } }