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) {