From f4f2d862e6d51c4fa4b2527960d4563dde91796c Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Mon, 12 Nov 2018 19:09:44 +0000 Subject: [PATCH] Fix deadlock in GraphiteWriter 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 | 2 +- lib/perfdata/graphitewriter.hpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index d58e2c53b..13be931d7 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -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; diff --git a/lib/perfdata/graphitewriter.hpp b/lib/perfdata/graphitewriter.hpp index 48a2f4203..1949c72a6 100644 --- a/lib/perfdata/graphitewriter.hpp +++ b/lib/perfdata/graphitewriter.hpp @@ -27,6 +27,7 @@ #include "base/timer.hpp" #include "base/workqueue.hpp" #include +#include 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; -- 2.40.0