diff --git a/lib/base/defer.hpp b/lib/base/defer.hpp index 33cc197db..9290c92b9 100644 --- a/lib/base/defer.hpp +++ b/lib/base/defer.hpp @@ -30,7 +30,11 @@ public: inline ~Defer() { - m_Func(); + try { + m_Func(); + } catch (...) { + // https://stackoverflow.com/questions/130117/throwing-exceptions-out-of-a-destructor + } } private: diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index 773f21a2a..b75cd7a3f 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -9,6 +9,7 @@ #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" #include "icinga/checkcommand.hpp" +#include "base/defer.hpp" #include "base/tcpsocket.hpp" #include "base/configtype.hpp" #include "base/objectlock.hpp" @@ -447,6 +448,8 @@ void InfluxdbWriter::Flush() if (!stream) return; + Defer close ([&stream]() { stream->Close(); }); + Url::Ptr url = new Url(); url->SetScheme(GetSslEnable() ? "https" : "http"); url->SetHost(GetHost());