Skip to content

Commit 08bb619

Browse files
authored
fix: Fix data race in ClusterCommunication (#2522)
1 parent 26ef25f commit 08bb619

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/cluster/ClusterCommunicationService.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <boost/asio/error.hpp>
3131
#include <boost/asio/spawn.hpp>
3232
#include <boost/asio/steady_timer.hpp>
33+
#include <boost/asio/use_future.hpp>
3334
#include <boost/json/parse.hpp>
3435
#include <boost/json/serialize.hpp>
3536
#include <boost/json/value.hpp>
@@ -127,7 +128,12 @@ ClusterCommunicationService::stop()
127128

128129
// for ASAN to see through concurrency correctly we need to exit all coroutines before joining the ctx
129130
running_ = false;
130-
cancelSignal_.emit(boost::asio::cancellation_type::all);
131+
132+
// cancelSignal_ is not thread safe so we execute emit on the same strand
133+
boost::asio::spawn(
134+
strand_, [this](auto&&) { cancelSignal_.emit(boost::asio::cancellation_type::all); }, boost::asio::use_future
135+
)
136+
.wait();
131137
finishedCountdown_.wait();
132138

133139
ctx_.join();

0 commit comments

Comments
 (0)