aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2020-03-05 22:27:07 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2020-03-06 03:54:35 +0000
commited0223ec59e5e7941abf17afd17ede393abea31b (patch)
tree0941a4b86930f2523a008adecc6a2373e96986cf
parent9828f9a9962c1bee5c343847030b9cfd87a40a5e (diff)
downloadbitcoin-ed0223ec59e5e7941abf17afd17ede393abea31b.tar.xz
scheduler: Workaround negative nsecs bug in boost's wait_until
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
-rw-r--r--src/scheduler.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/scheduler.cpp b/src/scheduler.cpp
index b01170074d..7fe340e0e9 100644
--- a/src/scheduler.cpp
+++ b/src/scheduler.cpp
@@ -56,8 +56,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