RedisConnection#Connect(): don't give up

This commit is contained in:
Alexander A. Klimov 2019-11-26 14:08:46 +01:00
parent e7ce71095a
commit e522db20b1

View File

@ -9,9 +9,9 @@
#include "base/objectlock.hpp"
#include "base/string.hpp"
#include "base/tcpsocket.hpp"
#include <boost/asio/post.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio.hpp>
#include <boost/coroutine/exceptions.hpp>
#include <boost/date_time/posix_time/posix_time_duration.hpp>
#include <boost/utility/string_view.hpp>
#include <boost/variant/get.hpp>
#include <exception>
@ -144,6 +144,9 @@ void RedisConnection::Connect(asio::yield_context& yc)
{
Defer notConnecting ([this]() { m_Connecting.store(m_Connected.load()); });
boost::asio::deadline_timer timer (m_Strand.context());
for (;;) {
try {
if (m_Path.IsEmpty()) {
Log(LogInformation, "IcingaDB")
@ -164,12 +167,19 @@ void RedisConnection::Connect(asio::yield_context& yc)
m_Connected.store(true);
Log(LogInformation, "IcingaDB", "Connected to Redis server");
break;
} catch (const boost::coroutines::detail::forced_unwind&) {
throw;
} catch (const std::exception& ex) {
Log(LogCritical, "IcingaDB")
<< "Cannot connect to " << m_Host << ":" << m_Port << ": " << ex.what();
}
timer.expires_from_now(boost::posix_time::seconds(5));
timer.async_wait(yc);
}
}
void RedisConnection::ReadLoop(asio::yield_context& yc)