From: Casey Bodley Date: Fri, 14 Sep 2018 18:41:30 +0000 (-0400) Subject: crimson/net: messenger uses dispatch gate for accept/connect callbacks X-Git-Tag: v14.0.1~266^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cabc60aaec68d6d3abafbd69f805693057ee9814;p=ceph.git crimson/net: messenger uses dispatch gate for accept/connect callbacks the dispatcher can throw to reject a new connection, so these callbacks were moved ahead of the exception handling Signed-off-by: Casey Bodley --- diff --git a/src/crimson/net/SocketMessenger.cc b/src/crimson/net/SocketMessenger.cc index 6ad0487ea6e7..35db46a1994b 100644 --- a/src/crimson/net/SocketMessenger.cc +++ b/src/crimson/net/SocketMessenger.cc @@ -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) {});