Skip to content

Commit c81a497

Browse files
Fix ineffective cancel() when stuck in perfdata writer handshake
Sometimes, the `stream->lowest_layer().cancel()` in `PerfdataWriterConnection::Disconnect()` is ineffective when `EnsureConnected()` is stuck in a handshake. Supposedly there is a window where the coroutine has already been suspended, but the handler for the SSL operations has not yet been queued. If the cancel hits in this window, it is entirely ignored. This is fixed by issuing a socket close unless the client is fully connected.
1 parent a12282e commit c81a497

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

lib/perfdata/perfdatawriterconnection.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,14 @@ void PerfdataWriterConnection::Disconnect()
7676
* completion.
7777
*/
7878
std::visit(
79-
[](const auto& stream) {
79+
[this](const auto& stream) {
8080
if (stream->lowest_layer().is_open()) {
81-
stream->lowest_layer().cancel();
81+
if (m_Connected) {
82+
stream->lowest_layer().cancel();
83+
} else {
84+
boost::system::error_code ec;
85+
stream->lowest_layer().close(ec);
86+
}
8287
}
8388
},
8489
m_Stream
@@ -160,7 +165,7 @@ void PerfdataWriterConnection::EnsureConnected(const boost::asio::yield_context&
160165

161166
void PerfdataWriterConnection::Disconnect(boost::asio::yield_context yc)
162167
{
163-
if (!m_Connected.exchange(false, std::memory_order_relaxed)) {
168+
if (!m_Connected.exchange(false)) {
164169
return;
165170
}
166171

0 commit comments

Comments
 (0)