From e2d9741af85a1ee8dcf70769473d63b948b5ec1b Mon Sep 17 00:00:00 2001 From: Davor Hirunda Date: Wed, 8 Jun 2022 22:02:40 +0000 Subject: [PATCH] Cancel the thread for sync blocks --- libraries/app/application.cpp | 9 +++++++++ libraries/net/node.cpp | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 56878eaf..d6324d7d 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -48,6 +48,7 @@ #include #include +#include #include #include @@ -107,6 +108,7 @@ public: fc::optional _lock_file; bool _is_block_producer = false; bool _force_validate = false; + std::atomic_bool _running{true}; void reset_p2p_node(const fc::path &data_dir) { try { @@ -450,6 +452,12 @@ public: */ virtual bool handle_block(const graphene::net::block_message &blk_msg, bool sync_mode, std::vector &contained_transaction_message_ids) override { + + // check point for the threads which may be cancled on application shutdown + if(!_running.load()) { + return true; + } + try { auto latency = fc::time_point::now() - blk_msg.block.timestamp; FC_ASSERT((latency.count() / 1000) > -5000, "Rejecting block with timestamp in the future"); @@ -1012,6 +1020,7 @@ void application::shutdown_plugins() { return; } void application::shutdown() { + my->_running.store(false); if (my->_p2p_network) my->_p2p_network->close(); if (my->_chain_db) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 0c95a419..841705f0 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -895,7 +895,7 @@ namespace graphene { namespace net { namespace detail { void node_impl::p2p_network_connect_loop() { VERIFY_CORRECT_THREAD(); - while (!_p2p_network_connect_loop_done.canceled()) + while (!_p2p_network_connect_loop_done.canceled() && !_node_is_shutting_down) { try { @@ -4051,6 +4051,8 @@ namespace graphene { namespace net { namespace detail { { VERIFY_CORRECT_THREAD(); + _node_is_shutting_down = true; + try { _potential_peer_db.close();