Skip to content

Commit

Permalink
Fixed an occasional deadlock on exit with merge mining active
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Jul 21, 2024
1 parent 8894da4 commit 0bada79
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/p2pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ p2pool::~p2pool()
}
#endif

std::vector<IMergeMiningClient*> 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);
Expand Down Expand Up @@ -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<hash> aux_id;

Expand Down Expand Up @@ -1026,19 +1031,20 @@ void p2pool::download_block_headers(uint64_t current_height)
}
}

{
WriteLock lock(m_mergeMiningClientsLock);

m_mergeMiningClients.clear();
std::vector<IMergeMiningClient*> 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;
}
}
Expand Down

0 comments on commit 0bada79

Please sign in to comment.