From: Michael Insel Date: Mon, 12 Nov 2018 19:09:44 +0000 (+0000) Subject: Fix deadlock in GraphiteWriter X-Git-Tag: v2.11.0-rc1~295^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=refs%2Fpull%2F6770%2Fhead;p=icinga2 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. --- 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;