]> granicus.if.org Git - icinga2/commitdiff
Fix deadlock in ApiClient::~ApiClient()
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 29 Sep 2015 14:03:38 +0000 (16:03 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 29 Sep 2015 14:03:38 +0000 (16:03 +0200)
refs #9976

lib/remote/jsonrpcconnection.cpp

index 128dfdc42809614260f6c6ab5de5d2c1a694d4d8..ed506511360831fdc2c503ecdda78d755a9a5374 100644 (file)
@@ -92,7 +92,8 @@ ConnectionRole JsonRpcConnection::GetRole(void) const
 
 void JsonRpcConnection::SendMessage(const Dictionary::Ptr& message)
 {
-       m_WriteQueue.Enqueue(boost::bind(&JsonRpcConnection::SendMessageSync, JsonRpcConnection::Ptr(this), message), true);
+       if (!m_Stream->IsEof())
+               m_WriteQueue.Enqueue(boost::bind(&JsonRpcConnection::SendMessageSync, JsonRpcConnection::Ptr(this), message), true);
 }
 
 void JsonRpcConnection::SendMessageSync(const Dictionary::Ptr& message)
@@ -108,7 +109,7 @@ void JsonRpcConnection::SendMessageSync(const Dictionary::Ptr& message)
                Log(LogWarning, "JsonRpcConnection")
                    << info.str() << "\n" << DiagnosticInformation(ex);
 
-               Disconnect();
+               Utility::QueueAsyncCallback(boost::bind(&JsonRpcConnection::Disconnect, JsonRpcConnection::Ptr(this)));
        }
 }
 
@@ -117,14 +118,16 @@ void JsonRpcConnection::Disconnect(void)
        Log(LogWarning, "JsonRpcConnection")
            << "API client disconnected for identity '" << m_Identity << "'";
 
+       m_Stream->Close();
+
+       m_WriteQueue.Join();
+
        if (m_Endpoint)
                m_Endpoint->RemoveClient(this);
        else {
                ApiListener::Ptr listener = ApiListener::GetInstance();
                listener->RemoveAnonymousClient(this);
        }
-
-       m_Stream->Close();
 }
 
 bool JsonRpcConnection::ProcessMessage(void)