From cac22fe38b42793f2f17d5d790ca926a7ecc56af Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 9 Feb 2022 16:10:57 +0100 Subject: [PATCH] RedisConnection#Connect(): wait for all promises to be completed by the read loop from the previous connection. --- lib/icingadb/redisconnection.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/icingadb/redisconnection.cpp b/lib/icingadb/redisconnection.cpp index 9bc62c0d2..f2ae3fa7b 100644 --- a/lib/icingadb/redisconnection.cpp +++ b/lib/icingadb/redisconnection.cpp @@ -262,6 +262,12 @@ void RedisConnection::Connect(asio::yield_context& yc) boost::asio::deadline_timer timer (m_Strand.context()); + auto waitForReadLoop ([this, &yc]() { + while (!m_Queues.FutureResponseActions.empty()) { + IoEngine::YieldCurrentCoroutine(yc); + } + }); + for (;;) { try { if (m_Path.IsEmpty()) { @@ -294,6 +300,7 @@ void RedisConnection::Connect(asio::yield_context& yc) } Handshake(conn, yc); + waitForReadLoop(); m_TlsConn = std::move(conn); } else { Log(m_Parent ? LogNotice : LogInformation, "IcingaDB") @@ -305,6 +312,7 @@ void RedisConnection::Connect(asio::yield_context& yc) icinga::Connect(conn->next_layer(), m_Host, Convert::ToString(m_Port), yc); Handshake(conn, yc); + waitForReadLoop(); m_TcpConn = std::move(conn); } } else { @@ -317,6 +325,7 @@ void RedisConnection::Connect(asio::yield_context& yc) conn->next_layer().async_connect(Unix::endpoint(m_Path.CStr()), yc); Handshake(conn, yc); + waitForReadLoop(); m_UnixConn = std::move(conn); }