Add a StoppableWaitGroup, and join it on #Stop(), to:

ApiListener
CheckerComponent
ExternalCommandListener
LivestatusListener
This commit is contained in:
Alexander A. Klimov 2025-05-22 17:34:37 +02:00
parent 18fb93fc11
commit c7cca7b460
8 changed files with 14 additions and 0 deletions

View File

@ -81,6 +81,7 @@ void CheckerComponent::Stop(bool runtimeRemoved)
m_CV.notify_all(); m_CV.notify_all();
} }
m_WaitGroup->Join();
m_ResultTimer->Stop(true); m_ResultTimer->Stop(true);
m_Thread.join(); m_Thread.join();

View File

@ -8,6 +8,7 @@
#include "base/configobject.hpp" #include "base/configobject.hpp"
#include "base/timer.hpp" #include "base/timer.hpp"
#include "base/utility.hpp" #include "base/utility.hpp"
#include "base/wait-group.hpp"
#include <boost/multi_index_container.hpp> #include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/key_extractors.hpp> #include <boost/multi_index/key_extractors.hpp>
@ -77,6 +78,7 @@ private:
CheckableSet m_IdleCheckables; CheckableSet m_IdleCheckables;
CheckableSet m_PendingCheckables; CheckableSet m_PendingCheckables;
StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup();
Timer::Ptr m_ResultTimer; Timer::Ptr m_ResultTimer;
void CheckThreadProc(); void CheckThreadProc();

View File

@ -50,6 +50,8 @@ void ExternalCommandListener::Start(bool runtimeCreated)
*/ */
void ExternalCommandListener::Stop(bool runtimeRemoved) void ExternalCommandListener::Stop(bool runtimeRemoved)
{ {
m_WaitGroup->Join();
Log(LogInformation, "ExternalCommandListener") Log(LogInformation, "ExternalCommandListener")
<< "'" << GetName() << "' stopped."; << "'" << GetName() << "' stopped.";

View File

@ -5,6 +5,7 @@
#include "compat/externalcommandlistener-ti.hpp" #include "compat/externalcommandlistener-ti.hpp"
#include "base/objectlock.hpp" #include "base/objectlock.hpp"
#include "base/wait-group.hpp"
#include "base/timer.hpp" #include "base/timer.hpp"
#include "base/utility.hpp" #include "base/utility.hpp"
#include <thread> #include <thread>
@ -29,6 +30,8 @@ protected:
void Stop(bool runtimeRemoved) override; void Stop(bool runtimeRemoved) override;
private: private:
StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup();
#ifndef _WIN32 #ifndef _WIN32
std::thread m_CommandThread; std::thread m_CommandThread;

View File

@ -112,6 +112,7 @@ void LivestatusListener::Stop(bool runtimeRemoved)
<< "'" << GetName() << "' stopped."; << "'" << GetName() << "' stopped.";
m_Listener->Close(); m_Listener->Close();
m_WaitGroup->Join();
if (m_Thread.joinable()) if (m_Thread.joinable())
m_Thread.join(); m_Thread.join();

View File

@ -7,6 +7,7 @@
#include "livestatus/livestatuslistener-ti.hpp" #include "livestatus/livestatuslistener-ti.hpp"
#include "livestatus/livestatusquery.hpp" #include "livestatus/livestatusquery.hpp"
#include "base/socket.hpp" #include "base/socket.hpp"
#include "base/wait-group.hpp"
#include <thread> #include <thread>
using namespace icinga; using namespace icinga;
@ -40,6 +41,7 @@ private:
Socket::Ptr m_Listener; Socket::Ptr m_Listener;
std::thread m_Thread; std::thread m_Thread;
StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup();
}; };
} }

View File

@ -368,6 +368,7 @@ void ApiListener::Stop(bool runtimeDeleted)
m_Timer->Stop(true); m_Timer->Stop(true);
m_RenewOwnCertTimer->Stop(true); m_RenewOwnCertTimer->Stop(true);
m_WaitGroup->Join();
ObjectImpl<ApiListener>::Stop(runtimeDeleted); ObjectImpl<ApiListener>::Stop(runtimeDeleted);
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")

View File

@ -16,6 +16,7 @@
#include "base/tcpsocket.hpp" #include "base/tcpsocket.hpp"
#include "base/tlsstream.hpp" #include "base/tlsstream.hpp"
#include "base/threadpool.hpp" #include "base/threadpool.hpp"
#include "base/wait-group.hpp"
#include <atomic> #include <atomic>
#include <boost/asio/io_context.hpp> #include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp> #include <boost/asio/ip/tcp.hpp>
@ -177,6 +178,7 @@ private:
Timer::Ptr m_RenewOwnCertTimer; Timer::Ptr m_RenewOwnCertTimer;
Endpoint::Ptr m_LocalEndpoint; Endpoint::Ptr m_LocalEndpoint;
StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup();
static ApiListener::Ptr m_Instance; static ApiListener::Ptr m_Instance;
static std::atomic<bool> m_UpdatedObjectAuthority; static std::atomic<bool> m_UpdatedObjectAuthority;