From 3c2b30e4c5dd2d0ea5f38feb8a05ad02bf9c3bd9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 12 Feb 2018 21:47:21 -0600 Subject: [PATCH] mon/MonClient: apply timeout while fetching config The normal timeouts automatically apply during the authenticate() stage, but not to the explicit wait for a config. If we don't get that quickly we shoudl retry another monitor because it is possible we will connect to an out-of-quorum (or otherwise unresponsive) mon. Signed-off-by: Sage Weil --- src/mon/MonClient.cc | 59 ++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index 2ccea89079f..b21eb3f9a82 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -98,8 +98,10 @@ int MonClient::get_monmap_and_config() ldout(cct, 10) << __func__ << dendl; assert(!messenger); + int tries = 10; + utime_t interval; - interval.set_from_double(cct->_conf->mon_client_hunt_interval * 10); + interval.set_from_double(cct->_conf->mon_client_hunt_interval); cct->init_crypto(); @@ -115,32 +117,41 @@ int MonClient::get_monmap_and_config() messenger->add_dispatcher_head(this); messenger->start(); - r = init(); - if (r < 0) { - goto out_msgr; - } - r = authenticate(cct->_conf->client_mount_timeout); - if (r < 0) { - goto out_shutdown; - } - if (!monmap.persistent_features.contains_all( - ceph::features::mon::FEATURE_MIMIC)) { - ldout(cct,10) << __func__ << " pre-mimic monitor, no config to fetch" - << dendl; - r = 0; - } else { - Mutex::Locker l(monc_lock); - while (!got_config) { - ldout(cct,20) << __func__ << " waiting for config" << dendl; - map_cond.WaitInterval(monc_lock, interval); + while (tries-- > 0) { + r = init(); + if (r < 0) { + goto out_msgr; + } + r = authenticate(cct->_conf->client_mount_timeout); + if (r == -ETIMEDOUT) { + shutdown(); + continue; } - if (got_config) { - ldout(cct,10) << __func__ << " success" << dendl; + if (r < 0) { + goto out_shutdown; + } + if (!monmap.persistent_features.contains_all( + ceph::features::mon::FEATURE_MIMIC)) { + ldout(cct,10) << __func__ << " pre-mimic monitor, no config to fetch" + << dendl; r = 0; - } else { - lderr(cct) << __func__ << " failed to get config" << dendl; - r = -EIO; + break; + } + { + Mutex::Locker l(monc_lock); + while (!got_config && r == 0) { + ldout(cct,20) << __func__ << " waiting for config" << dendl; + r = map_cond.WaitInterval(monc_lock, interval); + } + if (got_config) { + ldout(cct,10) << __func__ << " success" << dendl; + r = 0; + break; + } } + lderr(cct) << __func__ << " failed to get config" << dendl; + shutdown(); + continue; } out_shutdown: -- 2.39.5