From 2aca63cc9599c5e114d571ebb5299838a53129bc Mon Sep 17 00:00:00 2001 From: liwenhui-soul <38217397+liwenhui-soul@users.noreply.github.com> Date: Tue, 18 Jan 2022 20:46:07 +0800 Subject: [PATCH] fix deadlock when removing part --- src/kvstore/raftex/RaftexService.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/kvstore/raftex/RaftexService.cpp b/src/kvstore/raftex/RaftexService.cpp index ba7d926584f..e1ad239cc82 100644 --- a/src/kvstore/raftex/RaftexService.cpp +++ b/src/kvstore/raftex/RaftexService.cpp @@ -155,10 +155,17 @@ void RaftexService::addPartition(std::shared_ptr part) { } void RaftexService::removePartition(std::shared_ptr part) { - folly::RWSpinLock::WriteHolder wh(partsLock_); - parts_.erase(std::make_pair(part->spaceId(), part->partitionId())); + using FType = decltype(folly::makeFuture()); + using FTValype = typename FType::value_type; // Stop the partition - part->stop(); + folly::makeFuture() + .thenValue([this, &part](FTValype) { + folly::RWSpinLock::WriteHolder wh(partsLock_); + parts_.erase(std::make_pair(part->spaceId(), part->partitionId())); + }) + .via(getThreadManager().get()) + .thenValue([part](FTValype) { part->stop(); }) + .wait(); } std::shared_ptr RaftexService::findPart(GraphSpaceID spaceId, PartitionID partId) {