RedisConnection#Connect(): wait for all promises to be completed

by the read loop from the previous connection.
This commit is contained in:
Alexander A. Klimov 2022-02-09 16:10:57 +01:00
parent 9585a63fa0
commit cac22fe38b
1 changed files with 9 additions and 0 deletions

View File

@ -262,6 +262,12 @@ void RedisConnection::Connect(asio::yield_context& yc)
boost::asio::deadline_timer timer (m_Strand.context()); boost::asio::deadline_timer timer (m_Strand.context());
auto waitForReadLoop ([this, &yc]() {
while (!m_Queues.FutureResponseActions.empty()) {
IoEngine::YieldCurrentCoroutine(yc);
}
});
for (;;) { for (;;) {
try { try {
if (m_Path.IsEmpty()) { if (m_Path.IsEmpty()) {
@ -294,6 +300,7 @@ void RedisConnection::Connect(asio::yield_context& yc)
} }
Handshake(conn, yc); Handshake(conn, yc);
waitForReadLoop();
m_TlsConn = std::move(conn); m_TlsConn = std::move(conn);
} else { } else {
Log(m_Parent ? LogNotice : LogInformation, "IcingaDB") 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); icinga::Connect(conn->next_layer(), m_Host, Convert::ToString(m_Port), yc);
Handshake(conn, yc); Handshake(conn, yc);
waitForReadLoop();
m_TcpConn = std::move(conn); m_TcpConn = std::move(conn);
} }
} else { } else {
@ -317,6 +325,7 @@ void RedisConnection::Connect(asio::yield_context& yc)
conn->next_layer().async_connect(Unix::endpoint(m_Path.CStr()), yc); conn->next_layer().async_connect(Unix::endpoint(m_Path.CStr()), yc);
Handshake(conn, yc); Handshake(conn, yc);
waitForReadLoop();
m_UnixConn = std::move(conn); m_UnixConn = std::move(conn);
} }