From f074e24d2a1493132313a48b672155b0b9401df8 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 9 Feb 2024 14:44:52 +0100 Subject: [PATCH] ApiListener#ReplayLog(): stop reading files ASAP on send error --- lib/remote/apilistener.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index ab4a67b69..a05a5735e 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -1462,7 +1462,9 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client) return; } - for (;;) { + bool stopReplay = false; + + do { std::unique_lock lock(m_LogLock); CloseLogFile(); @@ -1545,6 +1547,7 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client) Log(LogDebug, "ApiListener") << "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex); + stopReplay = true; break; } @@ -1566,6 +1569,10 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client) } logStream->Close(); + + if (stopReplay) { + break; + } } if (count > 0) { @@ -1578,16 +1585,14 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client) } if (last_sync) { - { - ObjectLock olock2(endpoint); - endpoint->SetSyncing(false); - } - OpenLogFile(); break; } - } + } while (!stopReplay); + + ObjectLock olock2 (endpoint); + endpoint->SetSyncing(false); } void ApiListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)