Fix: keepalive exit without any message due to clock drift (#258)

Fix:  #257

Co-authored-by: qiupengfei <qiupengfei@baidu.com>
This commit is contained in:
penfree 2023-12-19 23:45:19 +08:00 committed by GitHub
parent 59635008c0
commit 84343ca9f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -1,4 +1,5 @@
#include <chrono>
#include <iostream>
#include <ratio>
#include "etcd/KeepAlive.hpp"
@ -177,7 +178,11 @@ void etcd::KeepAlive::refresh() {
std::unique_lock<std::mutex> lock(mutex_for_refresh_);
if (cv_for_refresh_.wait_for(lock, std::chrono::seconds(keepalive_ttl)) ==
std::cv_status::no_timeout) {
return;
if (!continue_next.load()) {
return;
}
std::cerr << "Warn: awaked from condition_variable" +
" but continue_next is not set, maybe due to clock drift." << std::endl;
}
}