aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-08-28 08:23:03 +0200
committerMarcoFalke <falke.marco@gmail.com>2020-08-28 08:23:15 +0200
commit89a6bb924571dfdda5376fa4de70921b1ccecdf3 (patch)
treee5f4f16067040da3e409e93b0b04f914206d166b
parent28a9df7d76a6bdd118cceacf31c5584325f45d8e (diff)
parented0223ec59e5e7941abf17afd17ede393abea31b (diff)
downloadbitcoin-89a6bb924571dfdda5376fa4de70921b1ccecdf3.tar.xz
Merge #18284: [0.19] scheduler: Workaround negative nsecs bug in boost's wait_until
ed0223ec59e5e7941abf17afd17ede393abea31b scheduler: Workaround negative nsecs bug in boost's wait_until (Luke Dashjr) Pull request description: Some boost versions have a bug that can cause a time prior to system boot (or wake from sleep) to throw an exception instead of return timeout See https://github.com/boostorg/thread/issues/308 NOTE: This was addressed in master with a refactor (#18234), so this isn't a strict backport and needs full review. Fixes #18227 Cleanly merges to 0.14+ ACKs for top commit: laanwj: ACK ed0223ec59e5e7941abf17afd17ede393abea31b gruve-p: ACK https://github.com/bitcoin/bitcoin/commit/ed0223ec59e5e7941abf17afd17ede393abea31b Tree-SHA512: 57edd0a22d7cf8f04b427e23d1ba10746a492638021d4438781b9d313dd0459418f64f0489be72d8e2286bbc8e8762d77e673868c25eb3bf4f0423a8fe8cdffa
-rw-r--r--src/scheduler.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/scheduler.cpp b/src/scheduler.cpp
index fdc859b3a0..b8b6d43420 100644
--- a/src/scheduler.cpp
+++ b/src/scheduler.cpp
@@ -63,8 +63,20 @@ void CScheduler::serviceQueue()
// Explicitly use a template here to avoid hitting that overload.
while (!shouldStop() && !taskQueue.empty()) {
boost::chrono::system_clock::time_point timeToWaitFor = taskQueue.begin()->first;
- if (newTaskScheduled.wait_until<>(lock, timeToWaitFor) == boost::cv_status::timeout)
- break; // Exit loop after timeout, it means we reached the time of the event
+ try {
+ if (newTaskScheduled.wait_until<>(lock, timeToWaitFor) == boost::cv_status::timeout) {
+ break; // Exit loop after timeout, it means we reached the time of the event
+ }
+ } catch (boost::thread_interrupted) {
+ // We need to make sure we don't ignore this, or the thread won't end
+ throw;
+ } catch (...) {
+ // Some boost versions have a bug that can cause a time prior to system boot (or wake from sleep) to throw an exception instead of return timeout
+ // See https://github.com/boostorg/thread/issues/308
+ // Check if the time has passed and, if so, break gracefully
+ if (timeToWaitFor <= boost::chrono::system_clock::now()) break;
+ throw;
+ }
}
#endif
// If there are multiple threads, the queue can empty while we're waiting (another