From 08bb6199640ea984b3ddca2cbbdd504cf6c7ec1c Mon Sep 17 00:00:00 2001 From: Sergey Kuznetsov Date: Thu, 4 Sep 2025 18:14:53 +0100 Subject: [PATCH] fix: Fix data race in ClusterCommunication (#2522) --- src/cluster/ClusterCommunicationService.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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();