]> granicus.if.org Git - icinga2/commitdiff
Fix deadlock in GraphiteWriter
authorMichael Insel <michael@insel.email>
Mon, 12 Nov 2018 19:09:44 +0000 (19:09 +0000)
committerMichael Friedrich <michael.friedrich@icinga.com>
Tue, 13 Nov 2018 08:13:55 +0000 (09:13 +0100)
This fixes a deadlock in the GraphiteWriter feature, which is visible
during the reload process. The reload thread waits for the
GraphiteWriter to finish, but the GraphiteWriter can't finish because
it's stuck in `SendMetric()` waiting for a lock which is hold by the
reload thread.

lib/perfdata/graphitewriter.cpp
lib/perfdata/graphitewriter.hpp

index d58e2c53ba1fccb01b514e2ee13b65df5793128b..13be931d715c63764a8b31a20a747cbe2e64cf9c 100644 (file)
@@ -282,7 +282,7 @@ void GraphiteWriter::SendMetric(const String& prefix, const String& name, double
        msgbuf << "\n";
        String metric = msgbuf.str();
 
-       ObjectLock olock(this);
+       boost::mutex::scoped_lock lock(m_StreamMutex);
 
        if (!GetConnected())
                return;
index 48a2f4203b82f403f01092de1f7d935caaaf7d6f..1949c72a60cd9cb8258a2ab07b42df1029451d1a 100644 (file)
@@ -27,6 +27,7 @@
 #include "base/timer.hpp"
 #include "base/workqueue.hpp"
 #include <fstream>
+#include <boost/thread/mutex.hpp>
 
 namespace icinga
 {
@@ -54,6 +55,7 @@ protected:
 
 private:
        Stream::Ptr m_Stream;
+       boost::mutex m_StreamMutex;
        WorkQueue m_WorkQueue{10000000, 1};
 
        Timer::Ptr m_ReconnectTimer;