More reliable p2pool shutdown logic

This commit is contained in:
SChernykh 2022-06-03 18:28:10 +02:00
parent 09f46beeb4
commit 05b0973a23
2 changed files with 29 additions and 2 deletions

View file

@ -413,6 +413,13 @@ void p2pool::submit_block_async(uint32_t template_id, uint32_t nonce, uint32_t e
m_submitBlockData.blob.clear();
}
// If p2pool is stopped, m_submitBlockAsync is most likely already closed
if (m_stopped) {
LOGWARN(0, "p2pool is shutting down, but a block was found. Trying to submit it anyway!");
submit_block();
return;
}
const int err = uv_async_send(&m_submitBlockAsync);
if (err) {
LOGERR(1, "uv_async_send failed, error " << uv_err_name(err));
@ -430,6 +437,13 @@ void p2pool::submit_block_async(const std::vector<uint8_t>& blob)
m_submitBlockData.blob = blob;
}
// If p2pool is stopped, m_submitBlockAsync is most likely already closed
if (m_stopped) {
LOGWARN(0, "p2pool is shutting down, but a block was found. Trying to submit it anyway!");
submit_block();
return;
}
const int err = uv_async_send(&m_submitBlockAsync);
if (err) {
LOGERR(1, "uv_async_send failed, error " << uv_err_name(err));
@ -574,6 +588,11 @@ void p2pool::submit_sidechain_block(uint32_t template_id, uint32_t nonce, uint32
void p2pool::update_block_template_async()
{
// If p2pool is stopped, m_blockTemplateAsync is most likely already closed
if (m_stopped) {
return;
}
const int err = uv_async_send(&m_blockTemplateAsync);
if (err) {
LOGERR(1, "uv_async_send failed, error " << uv_err_name(err));
@ -1403,11 +1422,19 @@ static bool init_signals(p2pool* pool)
void p2pool::stop()
{
// Can be called only once
if (m_stopped.exchange(true) == false) {
uv_async_send(&m_stopAsync);
}
}
void p2pool::restart_zmq()
{
// If p2pool is stopped, m_restartZMQAsync is most likely already closed
if (m_stopped) {
return;
}
if (!is_main_thread()) {
uv_async_send(&m_restartZMQAsync);
return;

View file

@ -108,7 +108,7 @@ private:
void submit_block() const;
bool m_stopped;
std::atomic<bool> m_stopped;
Params* m_params;