Skip to content

Commit a12282e

Browse files
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.
1 parent 5f01616 commit a12282e

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

lib/perfdata/perfdatawriterconnection.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool PerfdataWriterConnection::IsStopped() const
6262

6363
void PerfdataWriterConnection::Disconnect()
6464
{
65-
if (m_Stopped.exchange(true, std::memory_order_relaxed)) {
65+
if (m_Stopped.exchange(true)) {
6666
return;
6767
}
6868

@@ -133,6 +133,10 @@ void PerfdataWriterConnection::EnsureConnected(const boost::asio::yield_context&
133133
::Connect(stream->lowest_layer(), m_Host, m_Port, yc);
134134

135135
if constexpr (std::is_same_v<std::decay_t<decltype(stream)>, Shared<AsioTlsStream>::Ptr>) {
136+
if (m_Stopped) {
137+
BOOST_THROW_EXCEPTION(Stopped{});
138+
}
139+
136140
using type = boost::asio::ssl::stream_base::handshake_type;
137141

138142
stream->next_layer().async_handshake(type::client, yc);

0 commit comments

Comments
 (0)