From 1368ecd0b72f1387f0545c6deef9bd494b1aa7fe Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 18 Sep 2023 15:48:56 -0500 Subject: [PATCH] GH-1639 Fix producer_plugin shutdown of read only threads to prevent SEGFAULT and deadlock. --- .../custom_appbase/include/eosio/chain/application.hpp | 6 ++++++ .../custom_appbase/include/eosio/chain/exec_pri_queue.hpp | 3 ++- plugins/producer_plugin/producer_plugin.cpp | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/custom_appbase/include/eosio/chain/application.hpp b/libraries/custom_appbase/include/eosio/chain/application.hpp index 0e984d16f4..d4939fc418 100644 --- a/libraries/custom_appbase/include/eosio/chain/application.hpp +++ b/libraries/custom_appbase/include/eosio/chain/application.hpp @@ -119,6 +119,12 @@ class three_queue_executor { else return read_only_queue_.wrap( priority, --order_, std::forward( func)); } + + void stop() { + read_only_queue_.stop(); + read_write_queue_.stop(); + read_exclusive_queue_.stop(); + } void clear() { read_only_queue_.clear(); diff --git a/libraries/custom_appbase/include/eosio/chain/exec_pri_queue.hpp b/libraries/custom_appbase/include/eosio/chain/exec_pri_queue.hpp index 41716284af..bb0a6b62d4 100644 --- a/libraries/custom_appbase/include/eosio/chain/exec_pri_queue.hpp +++ b/libraries/custom_appbase/include/eosio/chain/exec_pri_queue.hpp @@ -14,7 +14,8 @@ class exec_pri_queue : public boost::asio::execution_context { public: - ~exec_pri_queue() { + void stop() { + std::lock_guard g( mtx_ ); exiting_blocking_ = true; cond_.notify_all(); } diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index d9272351c7..e6122f1704 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -1427,6 +1427,10 @@ void producer_plugin::plugin_startup() { void producer_plugin_impl::plugin_shutdown() { boost::system::error_code ec; _timer.cancel(ec); + boost::system::error_code ro_ec; + _ro_timer.cancel(ro_ec); + app().executor().stop(); + _ro_thread_pool.stop(); _thread_pool.stop(); _unapplied_transactions.clear();