diff --git a/src/server/replica.cc b/src/server/replica.cc index 2d8eda3a4..eb11723ad 100644 --- a/src/server/replica.cc +++ b/src/server/replica.cc @@ -67,6 +67,7 @@ vector> Partition(unsigned num_flows) { Replica::Replica(string host, uint16_t port, Service* se, std::string_view id) : ProtocolClient(std::move(host), port), service_(*se), id_{id} { + proactor_ = ProactorBase::me(); } Replica::~Replica() { @@ -133,8 +134,11 @@ void Replica::EnableReplication(ConnectionContext* cntx) { void Replica::Stop() { VLOG(1) << "Stopping replication"; // Stops the loop in MainReplicationFb. - state_mask_.store(0); // Specifically ~R_ENABLED. - cntx_.Cancel(); // Context is fully resposible for cleanup. + + proactor_->Await([this] { + cntx_.Cancel(); // Context is fully resposible for cleanup. + state_mask_.store(0); // Specifically ~R_ENABLED. + }); waker_.notifyAll(); diff --git a/src/server/replica.h b/src/server/replica.h index 86aed034f..181c10f26 100644 --- a/src/server/replica.h +++ b/src/server/replica.h @@ -156,6 +156,7 @@ class Replica : ProtocolClient { std::string GetSyncId() const; private: + util::fb2::ProactorBase* proactor_ = nullptr; Service& service_; MasterContext master_context_;