From 753600a2a045226759751891715ba9e7f79c5279 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Wed, 7 Nov 2018 09:30:59 -0800 Subject: [PATCH] Reset the validator list fetch timer if an error occurs --- src/ripple/app/misc/impl/ValidatorSite.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ripple/app/misc/impl/ValidatorSite.cpp b/src/ripple/app/misc/impl/ValidatorSite.cpp index 4229aed6d3..515f41a215 100644 --- a/src/ripple/app/misc/impl/ValidatorSite.cpp +++ b/src/ripple/app/misc/impl/ValidatorSite.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace ripple { @@ -152,11 +153,12 @@ void ValidatorSite::setTimer () { std::lock_guard lock{sites_mutex_}; - auto next = sites_.end(); - for (auto it = sites_.begin (); it != sites_.end (); ++it) - if (next == sites_.end () || it->nextRefresh < next->nextRefresh) - next = it; + auto next = std::min_element(sites_.begin(), sites_.end(), + [](Site const& a, Site const& b) + { + return a.nextRefresh < b.nextRefresh; + }); if (next != sites_.end ()) { @@ -164,8 +166,7 @@ ValidatorSite::setTimer () cv_.notify_all(); timer_.expires_at (next->nextRefresh); timer_.async_wait (std::bind (&ValidatorSite::onTimer, this, - std::distance (sites_.begin (), next), - std::placeholders::_1)); + std::distance (sites_.begin (), next), std::placeholders::_1)); } } @@ -213,12 +214,12 @@ ValidatorSite::onTimer ( std::size_t siteIdx, error_code const& ec) { - if (ec == boost::asio::error::operation_aborted) - return; if (ec) { - JLOG(j_.error()) << - "ValidatorSite::onTimer: " << ec.message(); + // Restart the timer if any errors are encountered, unless the error + // is from the wait operating being aborted due to a shutdown request. + if (ec != boost::asio::error::operation_aborted) + onSiteFetch(ec, detail::response_type {}, siteIdx); return; }