Skip to content

Commit 674d28b

Browse files
committed
fix hanging process
1 parent 8f98f6a commit 674d28b

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ To install or update LODA, please follow the [installation instructions](https:/
22

33
## [Unreleased]
44

5+
### Bugfixes
6+
7+
* Fix hanging process on initialization errors
8+
59
### Features
610

711
* Send miner alerts to Discord channel

src/mine/miner.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,25 @@ void Miner::reload() {
6161
manager->releaseStats(); // not needed anymore
6262
}
6363

64+
void shutdown() {
65+
if (!Signals::HALT) {
66+
Log::get().info("Signaling shutdown");
67+
Signals::HALT = true;
68+
}
69+
}
70+
6471
void Miner::mine() {
6572
if (progress_monitor) {
6673
// start background thread for progress monitoring
6774
auto monitor = progress_monitor;
68-
std::thread thread([monitor]() {
75+
std::thread monitor_thread([monitor]() {
6976
const auto delay = std::chrono::seconds(36); // 1% steps (magic number)
7077
while (!monitor->isTargetReached() && !Signals::HALT) {
7178
monitor->writeProgress();
7279
std::this_thread::sleep_for(delay);
7380
}
7481
monitor->writeProgress(); // final write
75-
Log::get().info("Initiating shutdown");
76-
Signals::HALT = true;
82+
shutdown();
7783
});
7884

7985
try {
@@ -86,15 +92,16 @@ void Miner::mine() {
8692
auto mins = std::to_string(monitor->getElapsedSeconds() / 60);
8793
Log::get().info("Finished mining after " + mins + " minutes");
8894
} catch (const std::exception &e) {
89-
Log::get().error("Caught exception during initialization or mining: " +
90-
std::string(e.what()),
91-
false);
92-
} catch (...) {
9395
Log::get().error(
94-
"Caught unknown exception during initialization or mining", false);
96+
"Error during initialization or mining: " + std::string(e.what()),
97+
false);
98+
shutdown();
99+
} catch (...) {
100+
Log::get().error("Unknown error during initialization or mining", false);
101+
shutdown();
95102
}
96103
try {
97-
thread.join();
104+
monitor_thread.join();
98105
} catch (...) {
99106
Log::get().warn("Error joining progress monitoring thread");
100107
}

0 commit comments

Comments
 (0)