From 55eb326a562b791082c2c0f42f4f3fee029668fd Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Wed, 22 Apr 2026 11:38:29 +0200 Subject: [PATCH] Fix a race-condition when perfdata writer is stuck in handshake The issue occurs when ::Connect in `EnsureConnected()` returns after `Disconnect()` has already set `m_Stopped` to true. By adding a check and throwing an exception before entering `async_handshake()` the behavior should now always be consistent. --- lib/perfdata/perfdatawriterconnection.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/perfdata/perfdatawriterconnection.cpp b/lib/perfdata/perfdatawriterconnection.cpp index 46000c28f..e8a56e899 100644 --- a/lib/perfdata/perfdatawriterconnection.cpp +++ b/lib/perfdata/perfdatawriterconnection.cpp @@ -62,7 +62,7 @@ bool PerfdataWriterConnection::IsStopped() const void PerfdataWriterConnection::Disconnect() { - if (m_Stopped.exchange(true, std::memory_order_relaxed)) { + if (m_Stopped.exchange(true)) { return; } @@ -133,6 +133,10 @@ void PerfdataWriterConnection::EnsureConnected(const boost::asio::yield_context& ::Connect(stream->lowest_layer(), m_Host, m_Port, yc); if constexpr (std::is_same_v, Shared::Ptr>) { + if (m_Stopped) { + BOOST_THROW_EXCEPTION(Stopped{}); + } + using type = boost::asio::ssl::stream_base::handshake_type; stream->next_layer().async_handshake(type::client, yc);