From: Gunnar Beutner Date: Mon, 23 Jun 2014 08:00:02 +0000 (+0200) Subject: Fix: Icinga doesn't send SetLogPosition messages when one of the endpoints fails... X-Git-Tag: v2.0.1~45 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=adccc41a8d81d2b688316e921d8e1085453a7609;p=icinga2 Fix: Icinga doesn't send SetLogPosition messages when one of the endpoints fails to connect fixes #6537 --- diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index e74841cb9..c666a701b 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -197,12 +197,11 @@ void ApiListener::ListenerThreadProc(const Socket::Ptr& server) } /** - * Creates a new JSON-RPC client and connects to the specified host and port. + * Creates a new JSON-RPC client and connects to the specified endpoint. * - * @param node The remote host. - * @param service The remote port. + * @param endpoint The endpoint. */ -void ApiListener::AddConnection(const String& node, const String& service) +void ApiListener::AddConnection(const Endpoint::Ptr& endpoint) { { ObjectLock olock(this); @@ -215,14 +214,21 @@ void ApiListener::AddConnection(const String& node, const String& service) } } + String host = endpoint->GetHost(); + String port = endpoint->GetPort(); + TcpSocket::Ptr client = make_shared(); try { - client->Connect(node, service); - Utility::QueueAsyncCallback(boost::bind(&ApiListener::NewClientHandler, this, client, RoleClient)); + endpoint->SetConnecting(true); + client->Connect(host, port); + NewClientHandler(client, RoleClient); + endpoint->SetConnecting(false); } catch (const std::exception& ex) { + endpoint->SetConnecting(false); + std::ostringstream info, debug; - info << "Cannot connect to host '" << node << "' on port '" << service << "'"; + info << "Cannot connect to host '" << host << "' on port '" << port << "'"; debug << info.str() << std::endl << DiagnosticInformation(ex); Log(LogCritical, "ApiListener", info.str()); Log(LogDebug, "ApiListener", debug.str()); @@ -358,7 +364,7 @@ void ApiListener::ApiTimerHandler(void) if (endpoint->GetHost().IsEmpty() || endpoint->GetPort().IsEmpty()) continue; - AddConnection(endpoint->GetHost(), endpoint->GetPort()); + Utility::QueueAsyncCallback(boost::bind(&ApiListener::AddConnection, this, endpoint)); } } } diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index a8a8609d9..8d95337d9 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -80,7 +80,7 @@ private: void ApiTimerHandler(void); void AddListener(const String& service); - void AddConnection(const String& node, const String& service); + void AddConnection(const Endpoint::Ptr& endpoint); void NewClientHandler(const Socket::Ptr& client, ConnectionRole role); void ListenerThreadProc(const Socket::Ptr& server); diff --git a/lib/remote/endpoint.ti b/lib/remote/endpoint.ti index cc06414db..2ea5e0ebf 100644 --- a/lib/remote/endpoint.ti +++ b/lib/remote/endpoint.ti @@ -16,6 +16,7 @@ class Endpoint : DynamicObject [state] double local_log_position; [state] double remote_log_position; + bool connecting; bool syncing; };