From ba7102cae37c2a112c2f9d696998a08cb08e36a0 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 13 Apr 2023 16:19:58 +0200 Subject: [PATCH] Explicitly stop started timers and wait for them before permitting their parent objects' destruction. For the cases where the handlers have raw pointers to these objects. --- lib/base/streamlogger.cpp | 2 +- lib/checker/checkercomponent.cpp | 2 +- lib/compat/compatlogger.cpp | 2 ++ lib/db_ido/dbconnection.cpp | 3 ++- lib/db_ido_mysql/idomysqlconnection.cpp | 3 ++- lib/db_ido_pgsql/idopgsqlconnection.cpp | 3 ++- lib/icingadb/icingadb.cpp | 2 ++ lib/notification/notificationcomponent.cpp | 2 ++ lib/perfdata/elasticsearchwriter.cpp | 2 ++ lib/perfdata/gelfwriter.cpp | 2 +- lib/perfdata/graphitewriter.cpp | 2 +- lib/perfdata/influxdbcommonwriter.cpp | 1 + lib/perfdata/opentsdbwriter.cpp | 2 +- lib/perfdata/perfdatawriter.cpp | 2 +- lib/remote/apilistener.cpp | 7 +++++++ 15 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index 4b01efbb3..162b9c3b0 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -28,7 +28,7 @@ void StreamLogger::Stop(bool runtimeRemoved) StreamLogger::~StreamLogger() { if (m_FlushLogTimer) - m_FlushLogTimer->Stop(); + m_FlushLogTimer->Stop(true); if (m_Stream && m_OwnsStream) delete m_Stream; diff --git a/lib/checker/checkercomponent.cpp b/lib/checker/checkercomponent.cpp index 64b628759..d92101f4e 100644 --- a/lib/checker/checkercomponent.cpp +++ b/lib/checker/checkercomponent.cpp @@ -81,7 +81,7 @@ void CheckerComponent::Stop(bool runtimeRemoved) m_CV.notify_all(); } - m_ResultTimer->Stop(); + m_ResultTimer->Stop(true); m_Thread.join(); Log(LogInformation, "CheckerComponent") diff --git a/lib/compat/compatlogger.cpp b/lib/compat/compatlogger.cpp index 543b1d95a..95ca830e1 100644 --- a/lib/compat/compatlogger.cpp +++ b/lib/compat/compatlogger.cpp @@ -82,6 +82,8 @@ void CompatLogger::Start(bool runtimeCreated) */ void CompatLogger::Stop(bool runtimeRemoved) { + m_RotationTimer->Stop(true); + Log(LogInformation, "CompatLogger") << "'" << GetName() << "' stopped."; diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 94db0b0e6..a8534c43a 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -101,7 +101,8 @@ void DbConnection::Pause() Log(LogInformation, "DbConnection") << "Pausing IDO connection: " << GetName(); - m_CleanUpTimer.reset(); + m_LogStatsTimer->Stop(true); + m_CleanUpTimer->Stop(true); DbQuery query1; query1.Table = "programstatus"; diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index 6e63f40a8..aacb7d7bd 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -108,7 +108,8 @@ void IdoMysqlConnection::Pause() DbConnection::Pause(); - m_ReconnectTimer.reset(); + m_ReconnectTimer->Stop(true); + m_TxTimer->Stop(true); #ifdef I2_DEBUG /* I2_DEBUG */ Log(LogDebug, "IdoMysqlConnection") diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index 663277425..07e88e6bb 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -112,7 +112,8 @@ void IdoPgsqlConnection::Pause() { DbConnection::Pause(); - m_ReconnectTimer.reset(); + m_ReconnectTimer->Stop(true); + m_TxTimer->Stop(true); Log(LogInformation, "IdoPgsqlConnection") << "'" << GetName() << "' paused."; diff --git a/lib/icingadb/icingadb.cpp b/lib/icingadb/icingadb.cpp index ae87ac11c..6d5ded9cf 100644 --- a/lib/icingadb/icingadb.cpp +++ b/lib/icingadb/icingadb.cpp @@ -195,6 +195,8 @@ void IcingaDB::Stop(bool runtimeRemoved) << m_HistoryBulker.Size() << " queued history queries."; } + m_StatsTimer->Stop(true); + Log(LogInformation, "IcingaDB") << "'" << GetName() << "' stopped."; diff --git a/lib/notification/notificationcomponent.cpp b/lib/notification/notificationcomponent.cpp index 9ba7103f4..982a8385f 100644 --- a/lib/notification/notificationcomponent.cpp +++ b/lib/notification/notificationcomponent.cpp @@ -52,6 +52,8 @@ void NotificationComponent::Start(bool runtimeCreated) void NotificationComponent::Stop(bool runtimeRemoved) { + m_NotificationTimer->Stop(true); + Log(LogInformation, "NotificationComponent") << "'" << GetName() << "' stopped."; diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 83ba2bec8..09ef31615 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -117,6 +117,8 @@ void ElasticsearchWriter::Pause() m_HandleStateChanges.disconnect(); m_HandleNotifications.disconnect(); + m_FlushTimer->Stop(true); + Flush(); m_WorkQueue.Join(); Flush(); diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index 34143fc75..79e76aaa3 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -112,7 +112,7 @@ void GelfWriter::Pause() m_HandleNotifications.disconnect(); m_HandleStateChanges.disconnect(); - m_ReconnectTimer.reset(); + m_ReconnectTimer->Stop(true); try { ReconnectInternal(); diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 51fe47e7b..6adae0233 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -107,7 +107,7 @@ void GraphiteWriter::Resume() void GraphiteWriter::Pause() { m_HandleCheckResults.disconnect(); - m_ReconnectTimer.reset(); + m_ReconnectTimer->Stop(true); try { ReconnectInternal(); diff --git a/lib/perfdata/influxdbcommonwriter.cpp b/lib/perfdata/influxdbcommonwriter.cpp index 19a0e8c78..5dbc29c51 100644 --- a/lib/perfdata/influxdbcommonwriter.cpp +++ b/lib/perfdata/influxdbcommonwriter.cpp @@ -113,6 +113,7 @@ void InfluxdbCommonWriter::Pause() Log(LogDebug, GetReflectionType()->GetName()) << "Processing pending tasks and flushing data buffers."; + m_FlushTimer->Stop(true); m_WorkQueue.Enqueue([this]() { FlushWQ(); }, PriorityLow); /* Wait for the flush to complete, implicitly waits for all WQ tasks enqueued prior to pausing. */ diff --git a/lib/perfdata/opentsdbwriter.cpp b/lib/perfdata/opentsdbwriter.cpp index c56bef916..2a9cfc046 100644 --- a/lib/perfdata/opentsdbwriter.cpp +++ b/lib/perfdata/opentsdbwriter.cpp @@ -92,7 +92,7 @@ void OpenTsdbWriter::Resume() void OpenTsdbWriter::Pause() { m_HandleCheckResults.disconnect(); - m_ReconnectTimer.reset(); + m_ReconnectTimer->Stop(true); Log(LogInformation, "OpentsdbWriter") << "'" << GetName() << "' paused."; diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 2bc3d9b95..849f19ed6 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -70,7 +70,7 @@ void PerfdataWriter::Resume() void PerfdataWriter::Pause() { m_HandleCheckResults.disconnect(); - m_RotationTimer.reset(); + m_RotationTimer->Stop(true); #ifdef I2_DEBUG //m_HostOutputFile << "\n# Pause the feature" << "\n\n"; diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 5c6813197..ad8bcad19 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -331,6 +331,13 @@ void ApiListener::RenewOwnCert() void ApiListener::Stop(bool runtimeDeleted) { + m_ApiPackageIntegrityTimer->Stop(true); + m_CleanupCertificateRequestsTimer->Stop(true); + m_AuthorityTimer->Stop(true); + m_ReconnectTimer->Stop(true); + m_Timer->Stop(true); + m_RenewOwnCertTimer->Stop(true); + ObjectImpl::Stop(runtimeDeleted); Log(LogInformation, "ApiListener")