From 68c5626d2ce17badba413bbfba9ff9e9de5a0464 Mon Sep 17 00:00:00 2001 From: Tao He Date: Tue, 15 Jun 2021 12:03:35 +0800 Subject: [PATCH] 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 --- src/KeepAlive.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/KeepAlive.cpp b/src/KeepAlive.cpp index a933edc..15fb2d2 100644 --- a/src/KeepAlive.cpp +++ b/src/KeepAlive.cpp @@ -101,6 +101,10 @@ etcd::KeepAlive::KeepAlive(std::string const & address, etcd::KeepAlive::~KeepAlive() { this->Cancel(); + // clean up + if (task_.joinable()) { + task_.join(); + } } void etcd::KeepAlive::Cancel() @@ -112,12 +116,7 @@ void etcd::KeepAlive::Cancel() if (keepalive_timer_) { keepalive_timer_->cancel(); } - - // clean up context.stop(); - if (task_.joinable()) { - task_.join(); - } } void etcd::KeepAlive::Check() {