From 9b5c5bd3c66ab08b33bc00a4b1b60bb303fec819 Mon Sep 17 00:00:00 2001 From: Tao He Date: Tue, 14 Feb 2023 21:20:12 +0800 Subject: [PATCH] Fixes the deadlock in keep alive (#191) Signed-off-by: Tao He --- etcd/v3/AsyncLeaseAction.hpp | 2 +- src/v3/AsyncLeaseAction.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/etcd/v3/AsyncLeaseAction.hpp b/etcd/v3/AsyncLeaseAction.hpp index b50b98a..f8fc972 100644 --- a/etcd/v3/AsyncLeaseAction.hpp +++ b/etcd/v3/AsyncLeaseAction.hpp @@ -62,7 +62,7 @@ namespace etcdv3 LeaseKeepAliveRequest req; bool isCancelled; - std::mutex protect_is_cancelled; + std::recursive_mutex protect_is_cancelled; friend class etcd::KeepAlive; }; diff --git a/src/v3/AsyncLeaseAction.cpp b/src/v3/AsyncLeaseAction.cpp index 8e6f34e..8415b54 100644 --- a/src/v3/AsyncLeaseAction.cpp +++ b/src/v3/AsyncLeaseAction.cpp @@ -97,7 +97,7 @@ etcdv3::AsyncLeaseKeepAliveResponse etcdv3::AsyncLeaseKeepAliveAction::ParseResp etcd::Response etcdv3::AsyncLeaseKeepAliveAction::Refresh() { - std::lock_guard scope_lock(this->protect_is_cancelled); + std::lock_guard scope_lock(this->protect_is_cancelled); auto start_timepoint = std::chrono::high_resolution_clock::now(); if (isCancelled) { @@ -171,7 +171,7 @@ etcd::Response etcdv3::AsyncLeaseKeepAliveAction::Refresh() void etcdv3::AsyncLeaseKeepAliveAction::CancelKeepAlive() { - std::lock_guard scope_lock(this->protect_is_cancelled); + std::lock_guard scope_lock(this->protect_is_cancelled); if(isCancelled == false) { isCancelled = true;