diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 81385e6da..efae05895 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -657,17 +657,22 @@ void ApiListener::NewClientHandlerInternal(boost::asio::yield_context yc, const if (ctype == ClientJsonRpc) { Log(LogNotice, "ApiListener", "New JSON-RPC client"); + if (endpoint && endpoint->GetConnected()) { + Log(LogNotice, "ApiListener") + << "Ignoring JSON-RPC connection " << conninfo + << ". We're already connected to Endpoint '" << endpoint->GetName() << "'."; + return; + } + JsonRpcConnection::Ptr aclient = new JsonRpcConnection(identity, verify_ok, client, role); if (endpoint) { - bool needSync = !endpoint->GetConnected(); - endpoint->AddClient(aclient); - IoEngine::SpawnCoroutine(IoEngine::Get().GetIoContext(), [this, aclient, endpoint, needSync](asio::yield_context yc) { + IoEngine::SpawnCoroutine(IoEngine::Get().GetIoContext(), [this, aclient, endpoint](asio::yield_context yc) { CpuBoundWork syncClient (yc); - SyncClient(aclient, endpoint, needSync); + SyncClient(aclient, endpoint, true); }); } else if (!AddAnonymousClient(aclient)) {