]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/net: allow connecting state reentrant
authorYingxin Cheng <yingxin.cheng@intel.com>
Wed, 7 Aug 2019 15:20:49 +0000 (23:20 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Mon, 12 Aug 2019 09:02:52 +0000 (17:02 +0800)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/net/ProtocolV2.cc
src/crimson/net/Socket.cc
src/crimson/net/Socket.h

index 63d682afd36315478b0e80f759549854c4e308cb..0c1ded6b1ccee2c7df209d65ecfa4c73a89cd65b 100644 (file)
@@ -843,6 +843,9 @@ ProtocolV2::client_reconnect()
 void ProtocolV2::execute_connecting()
 {
   trigger_state(state_t::CONNECTING, write_state_t::delay, true);
+  if (socket) {
+    socket->shutdown();
+  }
   seastar::with_gate(pending_dispatch, [this] {
       // we don't know my socket_port yet
       conn.set_ephemeral_port(0, SocketConnection::side_t::none);
@@ -860,16 +863,30 @@ void ProtocolV2::execute_connecting()
             logger().debug("{} UPDATE: gs={}, cc={} for connect",
                            conn, global_seq, client_cookie);
           }
+
+          return wait_write_exit();
+        }).then([this] {
+          if (unlikely(state != state_t::CONNECTING)) {
+            logger().debug("{} triggered {} before Socket::connect()",
+                           conn, get_state_name(state));
+            abort_protocol();
+          }
+          if (socket) {
+            with_gate(pending_dispatch, [this, sock = std::move(socket)] () mutable {
+              return sock->close().then([sock = std::move(sock)] {});
+            });
+          }
           return Socket::connect(conn.peer_addr);
         }).then([this](SocketFRef sock) {
           logger().debug("{} socket connected", conn);
-          socket = std::move(sock);
-          if (state == state_t::CLOSING) {
-            return socket->close().then([this] {
-              logger().warn("{} is closed during Socket::connect()", conn);
+          if (unlikely(state != state_t::CONNECTING)) {
+            logger().debug("{} triggered {} during Socket::connect()",
+                           conn, get_state_name(state));
+            return sock->close().then([this, sock = std::move(sock)] {
               abort_protocol();
             });
           }
+          socket = std::move(sock);
           return seastar::now();
         }).then([this] {
           auth_meta = seastar::make_lw_shared<AuthConnectionMeta>();
index ca4e80db5ddecabb1e4002c309ca75cdd8488824..763b4e2129c235cfa39e0d708ce3e58a370e94a9 100644 (file)
@@ -87,10 +87,6 @@ Socket::read_exactly(size_t bytes) {
 }
 
 void Socket::shutdown() {
-#ifndef NDEBUG
-  ceph_assert(!down);
-  down = true;
-#endif
   socket.shutdown_input();
   socket.shutdown_output();
 }
index fb3f037cdb56306b2d7bb7e0295d5793d826d23a..21de1db2b3cac565ab1f0e090e1f0b864c2cce91 100644 (file)
@@ -23,7 +23,6 @@ class Socket
   seastar::output_stream<char> out;
 
 #ifndef NDEBUG
-  bool down = false;
   bool closed = false;
 #endif