Skip to content

Commit 960ccd6

Browse files
committed
Don't process transactions/blocks when the working thread is finished
1 parent 8176991 commit 960ccd6

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

libraries/appbase/include/appbase/shutdown_mgr.hpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ namespace hive {
7070
std::map< hive_p2p_handler_type, shutdown_state::ptr_shutdown_state > states;
7171

7272
appbase::application& theApp;
73+
74+
plugins::chain::chain_plugin& chain;
7375

7476
const char* fStatus(std::future_status s)
7577
{
@@ -122,8 +124,8 @@ namespace hive {
122124

123125
public:
124126

125-
shutdown_mgr( std::string _name, appbase::application& app )
126-
: name( _name ), running( true ), theApp( app )
127+
shutdown_mgr( std::string _name, appbase::application& app, plugins::chain::chain_plugin& chain )
128+
: name( _name ), running( true ), theApp( app ), chain( chain )
127129
{
128130
std::map< hive_p2p_handler_type, std::string > input = {
129131
{ hive_p2p_handler_type::HIVE_P2P_BLOCK_HANDLER, "P2P_BLOCK" },
@@ -171,7 +173,14 @@ namespace hive {
171173

172174
bool is_running() const
173175
{
174-
return running.load() && !theApp.is_interrupt_request();
176+
/*
177+
Explanation of `is_finished_write_processing`.
178+
179+
Sometimes stopping of the working thread is triggered by SIGINT, but sometimes by CLI parameteres like `stop-at-block`.
180+
We have to have certanity that the working thread is closed regardless of a reason,
181+
so the best option is to wait for SIGINT and a real finish of the working thread.
182+
*/
183+
return running.load() && !theApp.is_interrupt_request() && !chain.is_finished_write_processing();
175184
}
176185

177186
shutdown_state& get_state( hive_p2p_handler_type handler )

libraries/plugins/chain/chain_plugin.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2069,4 +2069,10 @@ void chain_plugin::finish_request()
20692069
{
20702070
my->finish_request();
20712071
}
2072+
2073+
bool chain_plugin::is_finished_write_processing() const
2074+
{
2075+
return my->finish.status.load();
2076+
}
2077+
20722078
} } } // namespace hive::plugis::chain::chain_apis

libraries/plugins/chain/include/hive/plugins/chain/chain_plugin.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class chain_plugin : public plugin< chain_plugin >
149149
void disable_p2p( bool also_disable_work = true ) const;
150150

151151
void finish_request();
152+
bool is_finished_write_processing() const;
152153

153154
private:
154155
std::unique_ptr< detail::chain_plugin_impl, detail::chain_plugin_impl_deleter > my;

libraries/plugins/p2p/p2p_plugin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class p2p_plugin_impl : public graphene::net::node_delegate
7474
public:
7575

7676
p2p_plugin_impl( plugins::chain::chain_plugin& c, appbase::application& app )
77-
: shutdown_helper( "P2P plugin", c.get_app() ), chain( c ), theApp( app )
77+
: shutdown_helper( "P2P plugin", c.get_app(), c ), chain( c ), theApp( app )
7878
{
7979
}
8080
virtual ~p2p_plugin_impl()

0 commit comments

Comments
 (0)