From 4ee10a6c20802ecc2d1f933f4686334a7626deec Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 24 Aug 2023 17:48:09 +0200 Subject: [PATCH] GelfWriter: protect m_Stream via m_WorkQueue, not ObjectLock(this) On shutdown or HA re-connect ConfigObject#SetAuthority(false) is called which does ObjectLock(this) and ConfigObject#Pause(). GelfWriter#Pause(), with the above ObjectLock, calls m_WorkQueue.Join(). But items inside that also doing ObjectLock(this) cause a deadlock. --- lib/perfdata/gelfwriter.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index 79e76aaa3..c5b2bbd13 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -114,18 +114,17 @@ void GelfWriter::Pause() m_ReconnectTimer->Stop(true); - try { - ReconnectInternal(); - } catch (const std::exception&) { - Log(LogInformation, "GelfWriter") - << "'" << GetName() << "' paused. Unable to connect, not flushing buffers. Data may be lost on reload."; - - ObjectImpl::Pause(); - return; - } + m_WorkQueue.Enqueue([this]() { + try { + ReconnectInternal(); + } catch (const std::exception&) { + Log(LogInformation, "GelfWriter") + << "Unable to connect, not flushing buffers. Data may be lost."; + } + }, PriorityImmediate); + m_WorkQueue.Enqueue([this]() { DisconnectInternal(); }, PriorityLow); m_WorkQueue.Join(); - DisconnectInternal(); Log(LogInformation, "GelfWriter") << "'" << GetName() << "' paused."; @@ -513,8 +512,6 @@ void GelfWriter::SendLogMessage(const Checkable::Ptr& checkable, const String& g String log = msgbuf.str(); - ObjectLock olock(this); - if (!GetConnected()) return;