]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/net: avoid using finally
authorYingxin Cheng <yingxin.cheng@intel.com>
Mon, 30 Nov 2020 05:28:28 +0000 (13:28 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Tue, 1 Dec 2020 01:34:42 +0000 (09:34 +0800)
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 <yingxin.cheng@intel.com>
src/crimson/net/Protocol.cc
src/test/crimson/test_messenger.cc
src/test/crimson/test_socket.cc
src/tools/crimson/perf_crimson_msgr.cc

index 541f227e45d20dc4178d5d2519eb51b51a535f5b..6973aa5df5bc670681fa83ccb99f7cb15c8f6255 100644 (file)
@@ -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 {
index d5da8a94d027059b429c44c4951704a95ca272a9..0aac58a2a9080116f30469e5a1f04f3e0722b46d 100644 (file)
@@ -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<double> dur_handshake = session->connected_time - start_time;
           std::chrono::duration<double> 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<char>(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) {
index 5be99c08e6628f00d8ff48661b98a4c4cc56a022..f3485920f4e0c3376b2e24f6abe39d60f886706b 100644 (file)
@@ -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) {
index 710dc39fbd2bb17c387a07774952d0cc65214def..4acd01e0d32c82de8f5b47ef4d1ab6e328f1ed04 100644 (file)
@@ -40,7 +40,7 @@ seastar::future<T*> create_sharded(Args... args) {
     auto sharded_obj = seastar::make_lw_shared<seastar::sharded<T>>();
     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<double> dur_conn = conn_stats.connected_time - conn_stats.connecting_time;
           std::chrono::duration<double> 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)] {});
       });
     }