diff --git a/lib/icingadb/icingadb.cpp b/lib/icingadb/icingadb.cpp index 7641d9bcd..dec804f3d 100644 --- a/lib/icingadb/icingadb.cpp +++ b/lib/icingadb/icingadb.cpp @@ -73,22 +73,31 @@ void IcingaDB::Start(bool runtimeCreated) 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); } - auto connectedCallback ([this](boost::asio::yield_context& yc) { - m_WorkQueue.Enqueue([this]() { OnConnectedHandler(); }); - }); + m_PendingRcons = m_Rcons.size(); + + m_Rcon->SetConnectedCallback([this](boost::asio::yield_context& yc) { + m_Rcon->SetConnectedCallback(nullptr); - 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(); diff --git a/lib/icingadb/icingadb.hpp b/lib/icingadb/icingadb.hpp index 2f7d0f98c..92949a089 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 @@ -169,6 +170,7 @@ private: RedisConnection::Ptr m_Rcon; std::unordered_map m_Rcons; + std::atomic_size_t m_PendingRcons; struct { DumpedGlobals CustomVar, ActionUrl, NotesUrl, IconImage;