From cabc60aaec68d6d3abafbd69f805693057ee9814 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 14 Sep 2018 14:41:30 -0400 Subject: [PATCH] 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 --- src/crimson/net/SocketMessenger.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/crimson/net/SocketMessenger.cc b/src/crimson/net/SocketMessenger.cc index 6ad0487ea6e..35db46a1994 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) {}); -- 2.47.3