From: Yingxin Cheng Date: Mon, 30 Nov 2020 05:28:28 +0000 (+0800) Subject: crimson/net: avoid using finally X-Git-Tag: v16.1.0~416^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4698d3f001f4c2842d31ab98e393bd38aec7181f;p=ceph.git crimson/net: avoid using finally Messenger will only throw unexpected exceptions when there is a bug. In that case, we should not do any further operations which may result in segmentation fault and hide the original exception. Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/net/Protocol.cc b/src/crimson/net/Protocol.cc index 541f227e45d..6973aa5df5b 100644 --- a/src/crimson/net/Protocol.cc +++ b/src/crimson/net/Protocol.cc @@ -80,7 +80,7 @@ void Protocol::close(bool dispatch_reset, // asynchronous operations assert(!close_ready.valid()); - close_ready = std::move(gate_closed).finally([this] { + close_ready = std::move(gate_closed).then([this] { if (socket) { return socket->close(); } else { diff --git a/src/test/crimson/test_messenger.cc b/src/test/crimson/test_messenger.cc index d5da8a94d02..0aac58a2a90 100644 --- a/src/test/crimson/test_messenger.cc +++ b/src/test/crimson/test_messenger.cc @@ -157,7 +157,7 @@ static seastar::future<> test_echo(unsigned rounds, auto conn = msgr->connect(peer_addr, entity_name_t::TYPE_OSD); return seastar::futurize_invoke([this, conn] { return do_dispatch_pingpong(conn.get()); - }).finally([this, conn, start_time] { + }).then([this, conn, start_time] { auto session = find_session(conn.get()); std::chrono::duration dur_handshake = session->connected_time - start_time; std::chrono::duration dur_pingpong = session->finish_time - session->connected_time; @@ -242,19 +242,19 @@ static seastar::future<> test_echo(unsigned rounds, // shutdown }).then_unpack([] { return seastar::now(); - }).finally([client1] { + }).then([client1] { logger().info("client1 shutdown..."); return client1->shutdown(); - }).finally([client2] { + }).then([client2] { logger().info("client2 shutdown..."); return client2->shutdown(); - }).finally([server1] { + }).then([server1] { logger().info("server1 shutdown..."); return server1->shutdown(); - }).finally([server2] { + }).then([server2] { logger().info("server2 shutdown..."); return server2->shutdown(); - }).finally([server1, server2, client1, client2] { + }).then([server1, server2, client1, client2] { logger().info("test_echo() done!\n"); }); } @@ -352,15 +352,15 @@ static seastar::future<> test_concurrent_dispatch(bool v2) }); }).then([server] { return server->wait(); - }).finally([client] { + }).then([client] { logger().info("client shutdown..."); client->msgr->stop(); return client->msgr->shutdown(); - }).finally([server] { + }).then([server] { logger().info("server shutdown..."); server->msgr->stop(); return server->msgr->shutdown(); - }).finally([server, client] { + }).then([server, client] { logger().info("test_concurrent_dispatch() done!\n"); }); } @@ -472,10 +472,10 @@ seastar::future<> test_preemptive_shutdown(bool v2) { }).then([client] { logger().info("client shutdown..."); return client->shutdown(); - }).finally([server] { + }).then([server] { logger().info("server shutdown..."); return server->shutdown(); - }).finally([server, client] { + }).then([server, client] { logger().info("test_preemptive_shutdown() done!\n"); }); } @@ -1293,7 +1293,7 @@ class FailoverTest : public Dispatcher { m->cmd.emplace_back(1, static_cast(cmd_t::shutdown)); return cmd_conn->send(m).then([] { return seastar::sleep(200ms); - }).finally([this] { + }).then([this] { cmd_msgr->stop(); return cmd_msgr->shutdown(); }); @@ -1340,9 +1340,9 @@ class FailoverTest : public Dispatcher { logger().info("\n[FAIL: {}]", eptr); test_suite->dump_results(); throw; - }).finally([this] { + }).then([this] { return stop_peer(); - }).finally([this] { + }).then([this] { return test_suite->shutdown().then([this] { test_suite.reset(); }); @@ -3462,7 +3462,7 @@ test_v2_protocol(entity_addr_t test_addr, return FailoverTestPeer::create(test_peer_addr ).then([test_addr, test_peer_addr] (auto peer) { return test_v2_protocol(test_addr, test_peer_addr, false - ).finally([peer = std::move(peer)] () mutable { + ).then([peer = std::move(peer)] () mutable { return peer->wait().then([peer = std::move(peer)] {}); }); }).handle_exception([] (auto eptr) { @@ -3558,7 +3558,7 @@ test_v2_protocol(entity_addr_t test_addr, return test_v2_lossless_peer_connector(*test); }).then([test] { return test_v2_lossless_peer_acceptor(*test); - }).finally([test] { + }).then([test] { return test->shutdown().then([test] {}); }); }).handle_exception([] (auto eptr) { diff --git a/src/test/crimson/test_socket.cc b/src/test/crimson/test_socket.cc index 5be99c08e66..f3485920f4e 100644 --- a/src/test/crimson/test_socket.cc +++ b/src/test/crimson/test_socket.cc @@ -126,7 +126,7 @@ future<> test_accept() { return seastar::sleep(50ms); }).then([] { logger.info("test_accept() ok\n"); - }).finally([pss] { + }).then([pss] { return pss->destroy(); }).handle_exception([] (auto eptr) { logger.error("test_accept() got unexpeted exception {}", eptr); @@ -179,7 +179,7 @@ class SocketFactory { return seastar::now(); }).then([psf] { return psf->server_connected.get_future(); - }).finally([psf] { + }).then([psf] { if (psf->pss) { return seastar::smp::submit_to(1u, [psf] { return psf->pss->destroy(); @@ -193,7 +193,7 @@ class SocketFactory { return seastar::when_all_succeed( seastar::smp::submit_to(0u, [socket = psf->client_socket.get(), cb_client = std::move(cb_client)] { - return cb_client(socket).finally([socket] { + return cb_client(socket).then([socket] { logger.debug("closing client socket..."); return socket->close(); }).handle_exception([] (auto eptr) { @@ -204,7 +204,7 @@ class SocketFactory { }), seastar::smp::submit_to(1u, [socket = psf->server_socket.get(), cb_server = std::move(cb_server)] { - return cb_server(socket).finally([socket] { + return cb_server(socket).then([socket] { logger.debug("closing server socket..."); return socket->close(); }).handle_exception([] (auto eptr) { diff --git a/src/tools/crimson/perf_crimson_msgr.cc b/src/tools/crimson/perf_crimson_msgr.cc index 710dc39fbd2..4acd01e0d32 100644 --- a/src/tools/crimson/perf_crimson_msgr.cc +++ b/src/tools/crimson/perf_crimson_msgr.cc @@ -40,7 +40,7 @@ seastar::future create_sharded(Args... args) { auto sharded_obj = seastar::make_lw_shared>(); return sharded_obj->start(args...).then([sharded_obj]() { seastar::engine().at_exit([sharded_obj]() { - return sharded_obj->stop().finally([sharded_obj] {}); + return sharded_obj->stop().then([sharded_obj] {}); }); return sharded_obj.get(); }); @@ -621,7 +621,7 @@ static seastar::future<> run( } ).handle_exception_type([] (const DepthBroken& e) { // ok, stopped by stop_dispatch_messages() - }).finally([this, conn] { + }).then([this, conn] { std::chrono::duration dur_conn = conn_stats.connected_time - conn_stats.connecting_time; std::chrono::duration dur_msg = mono_clock::now() - conn_stats.start_time; unsigned ops = conn_stats.received_count - conn_stats.start_count; @@ -670,9 +670,9 @@ static seastar::future<> run( }).then([client, ramptime = client_conf.ramptime, msgtime = client_conf.msgtime] { return client->dispatch_with_timer(ramptime, msgtime); - }).finally([client] { + }).then([client] { return client->shutdown(); - }).finally([server, fp_server = std::move(fp_server)] () mutable { + }).then([server, fp_server = std::move(fp_server)] () mutable { return server->shutdown().then([cleanup = std::move(fp_server)] {}); }); } else if (mode == perf_mode_t::client) { @@ -685,7 +685,7 @@ static seastar::future<> run( }).then([client, ramptime = client_conf.ramptime, msgtime = client_conf.msgtime] { return client->dispatch_with_timer(ramptime, msgtime); - }).finally([client] { + }).then([client] { return client->shutdown(); }); } else { // mode == perf_mode_t::server @@ -696,7 +696,7 @@ static seastar::future<> run( ).then([server] { return server->wait(); // shutdown - }).finally([server, fp_server = std::move(fp_server)] () mutable { + }).then([server, fp_server = std::move(fp_server)] () mutable { return server->shutdown().then([cleanup = std::move(fp_server)] {}); }); }