From a35385a5c008dce629e62eb0e8b85823a9cb8cec Mon Sep 17 00:00:00 2001 From: Brannon King Date: Thu, 15 Apr 2021 21:15:40 -0400 Subject: [PATCH] backport wakeup fix --- src/scheduler.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 89dfc2b36..88f808275 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -64,8 +64,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