Skip to content

Commit

Permalink
JsonRpcConnection: Don't read any data on shutdown
Browse files Browse the repository at this point in the history
When the `Desconnect()` method is called, clients are not disconnected
immediately. Instead, a new coroutine is spawned using the same strand
as the other coroutines. This coroutine calls `async_shutdown` on the
TCP socket, which might be blocking. However, in order not to block
indefintely, the `Timeout` class cancels all operations on the socket
after `10` seconds. Though, the timeout does not trigger the handler
immediately; it creates spawns another coroutine using the same strand
as in the `JsonRpcConnection` class. This can cause unexpected delays if
e.g. `HandleIncomingMessages` gets resumed before the coroutine from the
timeout class. Apart from that, the coroutine for writing messages uses
the same condition, making the two symmetrical.
  • Loading branch information
yhabteab committed Oct 31, 2024
1 parent d894792 commit b9cbe94
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/remote/jsonrpcconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
{
m_Stream->next_layer().SetSeen(&m_Seen);

for (;;) {
while (!m_ShuttingDown) {
String message;

try {
message = JsonRpc::ReadMessage(m_Stream, yc, m_Endpoint ? -1 : 1024 * 1024);
} catch (const std::exception& ex) {
Log(m_ShuttingDown ? LogDebug : LogNotice, "JsonRpcConnection")
Log(LogNotice, "JsonRpcConnection")
<< "Error while reading JSON-RPC message for identity '" << m_Identity
<< "': " << DiagnosticInformation(ex);

Expand All @@ -84,7 +84,7 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)

l_TaskStats.InsertValue(Utility::GetTime(), 1);
} catch (const std::exception& ex) {
Log(m_ShuttingDown ? LogDebug : LogWarning, "JsonRpcConnection")
Log(LogWarning, "JsonRpcConnection")
<< "Error while processing JSON-RPC message for identity '" << m_Identity
<< "': " << DiagnosticInformation(ex);

Expand Down

0 comments on commit b9cbe94

Please sign in to comment.