From 4542b33e64a04adf305b15a6c9813f087f63658c Mon Sep 17 00:00:00 2001 From: Huang-Ming Huang Date: Fri, 6 Aug 2021 15:00:55 -0500 Subject: [PATCH] some code cleanup --- .../state_history_plugin.cpp | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/plugins/state_history_plugin/state_history_plugin.cpp b/plugins/state_history_plugin/state_history_plugin.cpp index cdb09d5c678..9c2a9cfa846 100644 --- a/plugins/state_history_plugin/state_history_plugin.cpp +++ b/plugins/state_history_plugin/state_history_plugin.cpp @@ -410,16 +410,14 @@ struct state_history_plugin_impl : std::enable_shared_from_thisplugin->stopping) return; - if (ec) - return on_fail(ec, what); + if (ec) { + fc_elog(_log, "${w}: ${m}", ("w", what)("m", ec.message())); + close_i(); + return; + } catch_and_close(f); } - void on_fail(boost::system::error_code ec, const char* what) { - fc_elog(_log, "${w}: ${m}", ("w", what)("m", ec.message())); - close_i(); - } - void close_i() { boost::system::error_code ec; socket_stream.next_layer().close(ec); @@ -733,18 +731,21 @@ void state_history_plugin::plugin_startup() { } void state_history_plugin::plugin_shutdown() { - my->applied_transaction_connection.reset(); - my->accepted_block_connection.reset(); - my->block_start_connection.reset(); - my->sessions.for_each([](auto& s) { s->close(); }); - my->stopping = true; - my->trace_log->stop(); - my->chain_state_log->stop(); - if (my->thr.joinable()) { - my->work_guard.reset(); - my->ctx.stop(); - my->thr.join(); + try { + my->applied_transaction_connection.reset(); + my->accepted_block_connection.reset(); + my->block_start_connection.reset(); + my->sessions.for_each([](auto& s) { s->close(); }); + my->stopping = true; + my->trace_log->stop(); + my->chain_state_log->stop(); + if (my->thr.joinable()) { + my->work_guard.reset(); + my->ctx.stop(); + my->thr.join(); + } } + FC_CAPTURE_LOG_AND_RETHROW(("")) } void state_history_plugin::handle_sighup() {