]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: take heartbeat_lock before checking for session
authorSage Weil <sage@redhat.com>
Fri, 26 Oct 2018 15:39:28 +0000 (10:39 -0500)
committerNathan Cutler <ncutler@suse.com>
Sat, 10 Nov 2018 14:32:38 +0000 (15:32 +0100)
When we open a connection, there is a short window before we attach
the session.  If a fault happens quickly, we won't get the reset, and
will persistently fail to send osd pings.

Move the lock up to avoid this.  Note that we should rarely really see
connections without sessions here anyway (except when this specific
race happens), so this should have no negative impact (by taking the lock
when we weren't before).

Fixes: http://tracker.ceph.com/issues/36602
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 51d8e2457d73c709bfa4f706793696b3ce704ff9)

Conflicts:
src/osd/OSD.cc
- use Mutex::Locker instead of std::lock_guard (latter is a C++17ism)

src/osd/OSD.cc

index 7d737433784c88616f8bc0dd1c5972bb5b3a8bf8..6e552267b982c8ce2c4fbe7c807f355b0c309238 100644 (file)
@@ -5255,9 +5255,9 @@ void OSD::heartbeat()
 
 bool OSD::heartbeat_reset(Connection *con)
 {
+  Mutex::Locker l(heartbeat_lock);
   HeartbeatSession *s = static_cast<HeartbeatSession*>(con->get_priv());
   if (s) {
-    heartbeat_lock.Lock();
     if (is_stopping()) {
       heartbeat_lock.Unlock();
       s->put();
@@ -5293,7 +5293,6 @@ bool OSD::heartbeat_reset(Connection *con)
     } else {
       dout(10) << "heartbeat_reset closing (old) failed hb con " << con << dendl;
     }
-    heartbeat_lock.Unlock();
     s->put();
   }
   return true;