From e7ce71095a7ec07fe659285b002881983056db09 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 21 Nov 2019 12:55:01 +0100 Subject: [PATCH] IcingaDB: handle Redis restarts --- lib/icingadb/redisconnection.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/icingadb/redisconnection.hpp b/lib/icingadb/redisconnection.hpp index 9f277f591..aaa525a6f 100644 --- a/lib/icingadb/redisconnection.hpp +++ b/lib/icingadb/redisconnection.hpp @@ -207,6 +207,8 @@ private: template RedisConnection::Reply RedisConnection::ReadOne(StreamPtr& stream, boost::asio::yield_context& yc) { + namespace asio = boost::asio; + if (!stream) { throw RedisDisconnected(); } @@ -221,6 +223,12 @@ RedisConnection::Reply RedisConnection::ReadOne(StreamPtr& stream, boost::asio:: if (m_Connecting.exchange(false)) { m_Connected.store(false); stream = nullptr; + + if (!m_Connecting.exchange(true)) { + Ptr keepAlive (this); + + asio::spawn(m_Strand, [this, keepAlive](asio::yield_context yc) { Connect(yc); }); + } } throw; @@ -230,6 +238,8 @@ RedisConnection::Reply RedisConnection::ReadOne(StreamPtr& stream, boost::asio:: template void RedisConnection::WriteOne(StreamPtr& stream, RedisConnection::Query& query, boost::asio::yield_context& yc) { + namespace asio = boost::asio; + if (!stream) { throw RedisDisconnected(); } @@ -245,6 +255,12 @@ void RedisConnection::WriteOne(StreamPtr& stream, RedisConnection::Query& query, if (m_Connecting.exchange(false)) { m_Connected.store(false); stream = nullptr; + + if (!m_Connecting.exchange(true)) { + Ptr keepAlive (this); + + asio::spawn(m_Strand, [this, keepAlive](asio::yield_context yc) { Connect(yc); }); + } } throw;