]> granicus.if.org Git - icinga2/commitdiff
Fix deadlock in {HttpServerConnection,JsonRpcConnection}::DataAvailableHandler
authorGunnar Beutner <gunnar@beutner.name>
Mon, 1 Feb 2016 07:35:55 +0000 (08:35 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 1 Feb 2016 07:35:55 +0000 (08:35 +0100)
refs #11014

lib/remote/httpserverconnection.cpp
lib/remote/jsonrpcconnection.cpp

index 3b533ca8bbb64a57a9e3db00fb300eb687ca801a..409b6f26e14528135e03674f3cfa6ea968096463 100644 (file)
@@ -78,7 +78,8 @@ void HttpServerConnection::Disconnect(void)
        ApiListener::Ptr listener = ApiListener::GetInstance();
        listener->RemoveHttpClient(this);
 
-       m_Stream->Shutdown();
+       if (!m_Stream->IsEof())
+               m_Stream->Shutdown();
 }
 
 bool HttpServerConnection::ProcessMessage(void)
@@ -196,21 +197,24 @@ void HttpServerConnection::ProcessMessageAsync(HttpRequest& request)
 
 void HttpServerConnection::DataAvailableHandler(void)
 {
-       boost::mutex::scoped_lock lock(m_DataHandlerMutex);
+       bool close = false;
 
-       try {
-               while (ProcessMessage())
-                       ; /* empty loop body */
-       } catch (const std::exception& ex) {
-               Log(LogWarning, "HttpServerConnection")
-                   << "Error while reading Http request: " << DiagnosticInformation(ex);
+       if (!m_Stream->IsEof()) {
+               boost::mutex::scoped_lock lock(m_DataHandlerMutex);
 
-               Disconnect();
+               try {
+                       while (ProcessMessage())
+                               ; /* empty loop body */
+               } catch (const std::exception& ex) {
+                       Log(LogWarning, "HttpServerConnection")
+                           << "Error while reading Http request: " << DiagnosticInformation(ex);
 
-               return;
-       }
+                       close = true;
+               }
+       } else
+               close = true;
 
-       if (m_Stream->IsEof())
+       if (close)
                Disconnect();
 }
 
index 00c953c444f9f6e9ba24c5510324fda54d92dbd6..b3cf8dbad07b134c232cdc46f12a32cf99a4d803 100644 (file)
@@ -227,22 +227,27 @@ bool JsonRpcConnection::ProcessMessage(void)
 
 void JsonRpcConnection::DataAvailableHandler(void)
 {
-       boost::mutex::scoped_lock lock(m_DataHandlerMutex);
+       bool close = false;
 
-       try {
-               while (ProcessMessage())
-                       ; /* empty loop body */
-       } catch (const std::exception& ex) {
-               Log(LogWarning, "JsonRpcConnection")
-                   << "Error while reading JSON-RPC message for identity '" << m_Identity
-                   << "': " << DiagnosticInformation(ex);
+       if (!m_Stream->IsEof()) {
+               boost::mutex::scoped_lock lock(m_DataHandlerMutex);
 
-               Disconnect();
+               try {
+                       while (ProcessMessage())
+                               ; /* empty loop body */
+               } catch (const std::exception& ex) {
+                       Log(LogWarning, "JsonRpcConnection")
+                           << "Error while reading JSON-RPC message for identity '" << m_Identity
+                           << "': " << DiagnosticInformation(ex);
 
-               return;
-       }
+                       Disconnect();
 
-       if (m_Stream->IsEof())
+                       return;
+               }
+       } else
+               close = true;
+
+       if (close)
                Disconnect();
 }