From 15cd1302ffae4e690e1934156e97d517c144960b Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 7 Nov 2024 13:22:03 +0100 Subject: [PATCH 1/2] JsonRpcConnection: don't write any data on shutdown In fact, this is already done for the outer loop (for each bulk), just not yet for the inner one (for each message of a bulk). So once the remote signals EOF, don't try to get things done until write error (which can't be associated with a particular message anyway, due to buffering), but just let the peer go. --- lib/remote/jsonrpcconnection.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index 44f1662dde1..253d0e38e26 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -110,6 +110,10 @@ void JsonRpcConnection::WriteOutgoingMessages(boost::asio::yield_context yc) if (!queue.empty()) { try { for (auto& message : queue) { + if (m_ShuttingDown) { + return; + } + size_t bytesSent = JsonRpc::SendRawMessage(m_Stream, message, yc); if (m_Endpoint) { From 3112e1fdd3c030fc0ebbe8e911c594af30246c7e Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 7 Nov 2024 13:23:28 +0100 Subject: [PATCH 2/2] JsonRpcConnection: don't flush any data on shutdown In fact, this is already done for both loops (for each bulk and for each message of it). So once the remote signals EOF, don't try to get things done until write error (which can't be associated with a particular message anyway, due to buffering), but just let the peer go. --- lib/remote/jsonrpcconnection.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index 253d0e38e26..38afd511672 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -121,6 +121,10 @@ void JsonRpcConnection::WriteOutgoingMessages(boost::asio::yield_context yc) } } + if (m_ShuttingDown) { + return; + } + m_Stream->async_flush(yc); } catch (const std::exception& ex) { Log(m_ShuttingDown ? LogDebug : LogWarning, "JsonRpcConnection")