From: Gunnar Beutner <gunnar@beutner.name>
Date: Tue, 11 Aug 2015 10:08:54 +0000 (+0200)
Subject: Fix crash during cluster log replay
X-Git-Tag: v2.4.0~432
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f600d75930d3d77385512ce81187bafdf0467df3;p=icinga2

Fix crash during cluster log replay

fixes #9876
---

diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp
index 84b89ad7f..13d32abb6 100644
--- a/lib/remote/apilistener.cpp
+++ b/lib/remote/apilistener.cpp
@@ -262,12 +262,22 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint)
 	}
 }
 
+void ApiListener::NewClientHandler(const Socket::Ptr& client, const String& hostname, ConnectionRole role)
+{
+	try {
+		NewClientHandler(client, hostname, role);
+	} catch (const std::exception& ex) {
+		Log(LogCritical, "ApiListener")
+		    << "Exception while handling new API client connection: " << DiagnosticInformation(ex);
+	}
+}
+
 /**
  * Processes a new client connection.
  *
  * @param client The new client.
  */
-void ApiListener::NewClientHandler(const Socket::Ptr& client, const String& hostname, ConnectionRole role)
+void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const String& hostname, ConnectionRole role)
 {
 	CONTEXT("Handling new API client connection");
 
diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp
index c7fccb38b..9842b5a38 100644
--- a/lib/remote/apilistener.hpp
+++ b/lib/remote/apilistener.hpp
@@ -93,6 +93,7 @@ private:
 	void AddConnection(const Endpoint::Ptr& endpoint);
 
 	void NewClientHandler(const Socket::Ptr& client, const String& hostname, ConnectionRole role);
+	void NewClientHandlerInternal(const Socket::Ptr& client, const String& hostname, ConnectionRole role);
 	void ListenerThreadProc(const Socket::Ptr& server);
 
 	WorkQueue m_RelayQueue;