From ed8156db28628b7c231fbaefaab41b3c371f2335 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Thu, 8 Feb 2024 11:15:53 +0100 Subject: [PATCH] Drop redundant `CpuBoundWork` usage in `JsonRpcConnection::Disconnect()` Although there is locking involved here, it shoudln't take too long for the thread to actually acquire it, since there aren't that many threads dealing with endpoint clients concurrently. It's just wasting pointless time trying to obtain a CPU slot. --- lib/remote/jsonrpcconnection.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index db35ef833..d5a8e46cb 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -197,14 +197,14 @@ void JsonRpcConnection::Disconnect() Log(LogWarning, "JsonRpcConnection") << "API client disconnected for identity '" << m_Identity << "'"; - { - CpuBoundWork removeClient (yc); - - if (m_Endpoint) { - m_Endpoint->RemoveClient(this); - } else { - ApiListener::GetInstance()->RemoveAnonymousClient(this); - } + // We need to unregister the endpoint client as soon as possible not to confuse Icinga 2, + // given that Endpoint::GetConnected() is just performing a check that the endpoint's client + // cache is not empty, which could result in an already disconnected endpoint never trying to + // reconnect again. See #7444. + if (m_Endpoint) { + m_Endpoint->RemoveClient(this); + } else { + ApiListener::GetInstance()->RemoveAnonymousClient(this); } m_OutgoingMessagesQueued.Set();