]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msgr: fix shutdown vs accept race
authorSage Weil <sage.weil@dreamhost.com>
Sat, 18 Feb 2012 21:45:37 +0000 (13:45 -0800)
committerSage Weil <sage@newdream.net>
Sat, 18 Feb 2012 22:28:44 +0000 (14:28 -0800)
This is a kludge.  The real fix is to rewrite SimpleMessenger as a state
machine.

Fixes: #2073
Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/msg/SimpleMessenger.cc

index 32eb818217b9230f0b5389fe3b857ffab9f4d1b0..a6898e37e28c60b36bb8868902b3025c2c11cd67 100644 (file)
@@ -729,6 +729,8 @@ int SimpleMessenger::Pipe::accept()
             << dendl;
     
     msgr->lock.Lock();
+    if (msgr->dispatch_queue.stop)
+      goto shutting_down;
 
     // note peer's type, flags
     set_peer_type(connect.host_type);
@@ -766,6 +768,9 @@ int SimpleMessenger::Pipe::accept()
       goto reply;
     }
     msgr->lock.Lock();
+    if (msgr->dispatch_queue.stop)
+      goto shutting_down;
+
     
     // existing?
     if (msgr->rank_pipe.count(peer_addr)) {
@@ -946,6 +951,8 @@ int SimpleMessenger::Pipe::accept()
   ldout(msgr->cct,10) << "accept features " << connection_state->get_features() << dendl;
 
   // ok!
+  if (msgr->dispatch_queue.stop)
+    goto shutting_down;
   register_pipe();
   msgr->lock.Unlock();
 
@@ -985,16 +992,25 @@ int SimpleMessenger::Pipe::accept()
 
  fail_unlocked:
   pipe_lock.Lock();
-  bool queued = is_queued();
-  if (queued)
-    state = STATE_CONNECTING;
-  else
-    state = STATE_CLOSED;
-  fault();
-  if (queued)
-    start_writer();
+  {
+    bool queued = is_queued();
+    if (queued && state != STATE_CLOSED)
+      state = STATE_CONNECTING;
+    else
+      state = STATE_CLOSED;
+    fault();
+    if (queued)
+      start_writer();
+  }
   pipe_lock.Unlock();
   return -1;
+
+ shutting_down:
+  msgr->lock.Unlock();
+  state = STATE_CLOSED;
+  fault();
+  msgr->lock.Unlock();
+  return -1;
 }
 
 int SimpleMessenger::Pipe::connect()