]> granicus.if.org Git - icinga2/commitdiff
Fix API crash with race condition on locks 5581/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Mon, 18 Sep 2017 13:25:29 +0000 (15:25 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 18 Sep 2017 13:25:29 +0000 (15:25 +0200)
This was split from #5416 and #5419.

More patches from #5419 are pending.

refs #5419
refs #5418
refs #5416

refs #5408
refs #5148
refs #5007
refs #4968
refs #4910

lib/remote/apilistener.cpp
lib/remote/apilistener.hpp

index 4adfcfa4221318411ef43e7f720f6ed6148c766f..45605dd6121cec4cbf092106d961cbc932e2b0c4 100644 (file)
@@ -1309,37 +1309,37 @@ double ApiListener::CalculateZoneLag(const Endpoint::Ptr& endpoint)
 
 void ApiListener::AddAnonymousClient(const JsonRpcConnection::Ptr& aclient)
 {
-       ObjectLock olock(this);
+       boost::mutex::scoped_lock(m_AnonymousClientsLock);
        m_AnonymousClients.insert(aclient);
 }
 
 void ApiListener::RemoveAnonymousClient(const JsonRpcConnection::Ptr& aclient)
 {
-       ObjectLock olock(this);
+       boost::mutex::scoped_lock(m_AnonymousClientsLock);
        m_AnonymousClients.erase(aclient);
 }
 
 std::set<JsonRpcConnection::Ptr> ApiListener::GetAnonymousClients(void) const
 {
-       ObjectLock olock(this);
+       boost::mutex::scoped_lock(m_AnonymousClientsLock);
        return m_AnonymousClients;
 }
 
 void ApiListener::AddHttpClient(const HttpServerConnection::Ptr& aclient)
 {
-       ObjectLock olock(this);
+       boost::mutex::scoped_lock(m_HttpClientsLock);
        m_HttpClients.insert(aclient);
 }
 
 void ApiListener::RemoveHttpClient(const HttpServerConnection::Ptr& aclient)
 {
-       ObjectLock olock(this);
+       boost::mutex::scoped_lock(m_HttpClientsLock);
        m_HttpClients.erase(aclient);
 }
 
 std::set<HttpServerConnection::Ptr> ApiListener::GetHttpClients(void) const
 {
-       ObjectLock olock(this);
+       boost::mutex::scoped_lock(m_HttpClientsLock);
        return m_HttpClients;
 }
 
index 665f96d27c90538d599e02d9de6d59807f02d1ed..e4d244f35903bd8145d26b1e0d675064af522710 100644 (file)
@@ -115,8 +115,12 @@ protected:
 private:
        boost::shared_ptr<SSL_CTX> m_SSLContext;
        std::set<TcpSocket::Ptr> m_Servers;
+
+       mutable boost::mutex m_AnonymousClientsLock;
+       mutable boost::mutex m_HttpClientsLock;
        std::set<JsonRpcConnection::Ptr> m_AnonymousClients;
        std::set<HttpServerConnection::Ptr> m_HttpClients;
+
        Timer::Ptr m_Timer;
        Timer::Ptr m_ReconnectTimer;
        Timer::Ptr m_AuthorityTimer;