From b0cf92fd173d5fe96095f9ebb1feaf13d7526cfd 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 a01f6c48b..1b6461d51 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -299,7 +299,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 6934d13b3..ec4c5bbfe 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;