]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/net: messenger uses dispatch gate for accept/connect callbacks
authorCasey Bodley <cbodley@redhat.com>
Fri, 14 Sep 2018 18:41:30 +0000 (14:41 -0400)
committerCasey Bodley <cbodley@redhat.com>
Fri, 14 Sep 2018 18:47:32 +0000 (14:47 -0400)
the dispatcher can throw to reject a new connection, so these callbacks
were moved ahead of the exception handling

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/crimson/net/SocketMessenger.cc

index 6ad0487ea6e76cd5fdb4791e326a0766e7b3e5a1..35db46a1994b869d9a241842a7b2ab0fa58962b2 100644 (file)
@@ -83,12 +83,16 @@ seastar::future<> SocketMessenger::accept(seastar::connected_socket socket,
                                             peer_addr, std::move(socket));
   // initiate the handshake
   return conn->server_handshake()
-    .handle_exception([conn] (std::exception_ptr eptr) {
+    .then([=] {
+      // notify the dispatcher and allow them to reject the connection
+      return seastar::with_gate(pending_dispatch, [=] {
+          return dispatcher->ms_handle_accept(conn);
+        });
+    }).handle_exception([conn] (std::exception_ptr eptr) {
       // close the connection before returning errors
       return seastar::make_exception_future<>(eptr)
         .finally([conn] { return conn->close(); });
     }).then([this, conn] {
-      dispatcher->ms_handle_accept(conn);
       // dispatch messages until the connection closes or the dispatch
       // queue shuts down
       return dispatch(std::move(conn));
@@ -133,13 +137,17 @@ SocketMessenger::connect(const entity_addr_t& addr, entity_type_t peer_type)
                                                 std::move(socket));
       // complete the handshake before returning to the caller
       return conn->client_handshake(peer_type, get_myname().type())
-        .handle_exception([conn] (std::exception_ptr eptr) {
+        .then([=] {
+          // notify the dispatcher and allow them to reject the connection
+          return seastar::with_gate(pending_dispatch, [=] {
+            return dispatcher->ms_handle_connect(conn);
+          });
+        }).handle_exception([conn] (std::exception_ptr eptr) {
           // close the connection before returning errors
           return seastar::make_exception_future<>(eptr)
             .finally([conn] { return conn->close(); });
          // TODO: retry on fault
         }).then([=] {
-          dispatcher->ms_handle_connect(conn);
           // dispatch replies on this connection
           dispatch(conn)
             .handle_exception([] (std::exception_ptr eptr) {});