From 96c581b2f6ca2d5c60775e34042bff7725b17f6e Mon Sep 17 00:00:00 2001 From: Yusuke Nojima Date: Tue, 9 Jul 2024 11:34:18 +0900 Subject: [PATCH] JTASK-1062: always retry connection to master --- src/memcache/handler.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/memcache/handler.cpp b/src/memcache/handler.cpp index 975bfed..88acda1 100644 --- a/src/memcache/handler.cpp +++ b/src/memcache/handler.cpp @@ -149,10 +149,19 @@ void handler::on_master_end() { } bool handler::on_slave_start() { + using logger = cybozu::logger; + auto master_host = g_config.master_host(); - int fd = cybozu::tcp_connect(master_host.c_str(), - g_config.repl_port()); + int fd; + try { + fd = cybozu::tcp_connect(master_host.c_str(), g_config.repl_port()); + } catch( std::runtime_error& err ) { + logger::error() << "Failed to connect to the master (" << master_host << "): " << err.what(); + m_reactor.run_once(); + return false; + } if( fd == -1 ) { + logger::error() << "Failed to connect to the master (" << master_host << ")"; m_reactor.run_once(); return false; }