diff --git a/lib/icingadb/icingadb.cpp b/lib/icingadb/icingadb.cpp index a7eb3753e..dec804f3d 100644 --- a/lib/icingadb/icingadb.cpp +++ b/lib/icingadb/icingadb.cpp @@ -68,30 +68,39 @@ void IcingaDB::Start(bool runtimeCreated) GetEnableTls(), GetInsecureNoverify(), GetCertPath(), GetKeyPath(), GetCaPath(), GetCrlPath(), GetTlsProtocolmin(), GetCipherList(), GetConnectTimeout(), GetDebugInfo()); - auto connectedCallback ([this](boost::asio::yield_context& yc) { - m_WorkQueue.Enqueue([this]() { OnConnectedHandler(); }); - }); - - m_Rcon->SetConnectedCallback([this, connectedCallback](boost::asio::yield_context& yc) { - for (auto& kv : m_Rcons) { - kv.second->Start(); - } - - m_Rcon->SetConnectedCallback(connectedCallback); - connectedCallback(yc); - }); - m_Rcon->Start(); - for (const Type::Ptr& type : GetTypes()) { auto ctype (dynamic_cast(type.get())); if (!ctype) continue; - m_Rcons[ctype] = new RedisConnection(GetHost(), GetPort(), GetPath(), GetPassword(), GetDbIndex(), + RedisConnection::Ptr con = new RedisConnection(GetHost(), GetPort(), GetPath(), GetPassword(), GetDbIndex(), GetEnableTls(), GetInsecureNoverify(), GetCertPath(), GetKeyPath(), GetCaPath(), GetCrlPath(), GetTlsProtocolmin(), GetCipherList(), GetConnectTimeout(), GetDebugInfo(), m_Rcon); + + con->SetConnectedCallback([this, con](boost::asio::yield_context& yc) { + con->SetConnectedCallback(nullptr); + + size_t pending = --m_PendingRcons; + Log(LogDebug, "IcingaDB") << pending << " pending child connections remaining"; + if (pending == 0) { + m_WorkQueue.Enqueue([this]() { OnConnectedHandler(); }); + } + }); + + m_Rcons[ctype] = std::move(con); } + m_PendingRcons = m_Rcons.size(); + + m_Rcon->SetConnectedCallback([this](boost::asio::yield_context& yc) { + m_Rcon->SetConnectedCallback(nullptr); + + for (auto& kv : m_Rcons) { + kv.second->Start(); + } + }); + m_Rcon->Start(); + m_StatsTimer = new Timer(); m_StatsTimer->SetInterval(1); m_StatsTimer->OnTimerExpired.connect([this](const Timer * const&) { PublishStatsTimerHandler(); }); diff --git a/lib/icingadb/icingadb.hpp b/lib/icingadb/icingadb.hpp index 1365efd7a..df49fd17d 100644 --- a/lib/icingadb/icingadb.hpp +++ b/lib/icingadb/icingadb.hpp @@ -13,6 +13,7 @@ #include "icinga/downtime.hpp" #include "remote/messageorigin.hpp" #include +#include #include #include #include @@ -170,6 +171,7 @@ private: RedisConnection::Ptr m_Rcon; std::unordered_map m_Rcons; + std::atomic_size_t m_PendingRcons; struct { DumpedGlobals CustomVar, ActionUrl, NotesUrl, IconImage;