From 82afbb6003fc98bcbefec69f736f941f94df99fa Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 6 Feb 2010 11:27:17 -0800 Subject: [PATCH] monc: fix authentication timeout --- src/mon/MonClient.cc | 16 ++++++++++++++-- src/mon/MonClient.h | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index fd4509718e3b..a1323c988858 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -272,8 +272,20 @@ int MonClient::authenticate(double timeout) if (cur_mon < 0) _reopen_session(); - while (state != MC_STATE_HAVE_SESSION && !authenticate_err) - auth_cond.Wait(monc_lock); + utime_t until = g_clock.now(); + until += timeout; + if (timeout > 0.0) + dout(10) << "authenticate will time out at " << until << dendl; + while (state != MC_STATE_HAVE_SESSION && !authenticate_err) { + if (timeout > 0.0) { + int r = auth_cond.WaitUntil(monc_lock, until); + if (r == ETIMEDOUT) { + dout(0) << "authenticate timed out after " << timeout << dendl; + authenticate_err = -r; + } + } else + auth_cond.Wait(monc_lock); + } if (state == MC_STATE_HAVE_SESSION) { dout(5) << "authenticate success, global_id " << global_id << dendl; diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h index 699dd378df19..eb4b4ccd08b0 100644 --- a/src/mon/MonClient.h +++ b/src/mon/MonClient.h @@ -109,7 +109,7 @@ public: int _check_auth_rotating(); int wait_auth_rotating(double timeout); - int authenticate(double timeout=30.0); + int authenticate(double timeout=0.0); // mon subscriptions private: -- 2.47.3