aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic/miner.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-03-14 16:54:03 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-03-14 16:59:08 +0000
commit39f000b3948e64a38b14b1d358ced1b2d1f44bf3 (patch)
tree16f55142e3c0b85ac0347eef25df25e02f982b01 /src/cryptonote_basic/miner.cpp
parentMerge pull request #5258 (diff)
downloadmonero-39f000b3948e64a38b14b1d358ced1b2d1f44bf3.tar.xz
miner: fix possible exit crash due to race in stop
If a thread asks to stop the miner, m_stop will be set, and that thread will wait to join. If the main thread is exiting at that time, it will ask the miner to stop, but the miner will claim it's not mining and early out since m_stop is set. This will cause the database and other things to get shutdown. If the miner happens to find a block at that time, it will try to call core, and crash. Instead, lock and check whether any threads are currently in m_threads, since they'll only be cleared once the threads are joined. Moreover, since we lock, the second thread will have to wait for the first one to have finished. Calling join twice on a thread seems fine as per pthread_join(3).
Diffstat (limited to 'src/cryptonote_basic/miner.cpp')
-rw-r--r--src/cryptonote_basic/miner.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp
index 3a51c6ea4..1e211d00b 100644
--- a/src/cryptonote_basic/miner.cpp
+++ b/src/cryptonote_basic/miner.cpp
@@ -432,14 +432,15 @@ namespace cryptonote
{
MTRACE("Miner has received stop signal");
- if (!is_mining())
+ CRITICAL_REGION_LOCAL(m_threads_lock);
+ bool mining = !m_threads.empty();
+ if (!mining)
{
MTRACE("Not mining - nothing to stop" );
return true;
}
send_stop_signal();
- CRITICAL_REGION_LOCAL(m_threads_lock);
// In case background mining was active and the miner threads are waiting
// on the background miner to signal start.