diff options
-rw-r--r-- | src/Database.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/Database.cpp b/src/Database.cpp index 27caba0..155e8f5 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -144,8 +144,9 @@ namespace odhtdb delete ntpThread; const int ntpFetchTimestampRetries = 5; + const int ntpFetchFailRetryCooldownSec = 60; - ntpThread = new thread([]() + ntpThread = new thread([ntpFetchFailRetryCooldownSec]() { ntp::NtpClient ntpClient("pool.ntp.org", 10); while(databaseCount > 0) @@ -166,17 +167,30 @@ namespace odhtdb catch(ntp::NtpClientException &e) { Log::warn("Failed to sync clock with ntp server, reason: %s. Try #%d", e.what(), fetchRetryCounter); - this_thread::sleep_for(500ms); + if(timestampSynced) + this_thread::sleep_for(3s); } ++fetchRetryCounter; } if(fetchRetryCounter == ntpFetchTimestampRetries) - throw ntp::NtpClientException("Failed to retrieve ntp timestamp after several retries"); + { + if(!timestampSynced) + { + string errMsg = "Failed to retrieve ntp timestamp after "; + errMsg += to_string(ntpFetchTimestampRetries); + errMsg += " retries, giving up"; + throw ntp::NtpClientException(errMsg); + } + else + { + Log::warn("Failed to retrieve ntp timestamp after %d retries, retrying in %d seconds", ntpFetchTimestampRetries, ntpFetchFailRetryCooldownSec); + this_thread::sleep_for(chrono::seconds(ntpFetchFailRetryCooldownSec)); + } + } this_thread::sleep_for(60s); } - timestampSynced = false; }); ntpThread->detach(); } |