Keepalive: join the thread outside the background job itself.
Fixes #67, when etcd server stops, the keepalive action will crash. Signed-off-by: Tao He <sighingnow@gmail.com>
This commit is contained in:
parent
b3a193c75e
commit
68c5626d2c
|
|
@ -101,6 +101,10 @@ etcd::KeepAlive::KeepAlive(std::string const & address,
|
||||||
etcd::KeepAlive::~KeepAlive()
|
etcd::KeepAlive::~KeepAlive()
|
||||||
{
|
{
|
||||||
this->Cancel();
|
this->Cancel();
|
||||||
|
// clean up
|
||||||
|
if (task_.joinable()) {
|
||||||
|
task_.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void etcd::KeepAlive::Cancel()
|
void etcd::KeepAlive::Cancel()
|
||||||
|
|
@ -112,12 +116,7 @@ void etcd::KeepAlive::Cancel()
|
||||||
if (keepalive_timer_) {
|
if (keepalive_timer_) {
|
||||||
keepalive_timer_->cancel();
|
keepalive_timer_->cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean up
|
|
||||||
context.stop();
|
context.stop();
|
||||||
if (task_.joinable()) {
|
|
||||||
task_.join();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void etcd::KeepAlive::Check() {
|
void etcd::KeepAlive::Check() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue