diff --git a/src/cluster/ClusterCommunicationService.cpp b/src/cluster/ClusterCommunicationService.cpp index f714549c..a0aba56b 100644 --- a/src/cluster/ClusterCommunicationService.cpp +++ b/src/cluster/ClusterCommunicationService.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -127,7 +128,12 @@ ClusterCommunicationService::stop() // for ASAN to see through concurrency correctly we need to exit all coroutines before joining the ctx running_ = false; - cancelSignal_.emit(boost::asio::cancellation_type::all); + + // cancelSignal_ is not thread safe so we execute emit on the same strand + boost::asio::spawn( + strand_, [this](auto&&) { cancelSignal_.emit(boost::asio::cancellation_type::all); }, boost::asio::use_future + ) + .wait(); finishedCountdown_.wait(); ctx_.join();