From db7a056ceeb76c39c85ba57300d810200d43d56b Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Wed, 22 Apr 2026 11:42:31 +0200 Subject: [PATCH] Fix ineffective cancel() when stuck in perfdata writer handshake --- lib/perfdata/perfdatawriterconnection.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/perfdata/perfdatawriterconnection.cpp b/lib/perfdata/perfdatawriterconnection.cpp index e8a56e899..c8cc80e9d 100644 --- a/lib/perfdata/perfdatawriterconnection.cpp +++ b/lib/perfdata/perfdatawriterconnection.cpp @@ -76,9 +76,13 @@ void PerfdataWriterConnection::Disconnect() * completion. */ std::visit( - [](const auto& stream) { + [&](const auto& stream) { if (stream->lowest_layer().is_open()) { - stream->lowest_layer().cancel(); + if (m_Connected) { + stream->lowest_layer().cancel(); + } else { + stream->lowest_layer().close(); + } } }, m_Stream @@ -160,7 +164,7 @@ void PerfdataWriterConnection::EnsureConnected(const boost::asio::yield_context& void PerfdataWriterConnection::Disconnect(boost::asio::yield_context yc) { - if (!m_Connected.exchange(false, std::memory_order_relaxed)) { + if (!m_Connected.exchange(false)) { return; }