Skip to content

Commit

Permalink
Fix problem with keepalive timer sometimes causing a crash on exit be…
Browse files Browse the repository at this point in the history
…cause plugin_shutdown not called. Moved the creation of keepalive timer to after acceptor bind which can easily fail if port already in use. Changed fc_elog to elog for port already in use so that it is always logged regardless of net_plugin_impl logger setting. Also move the setup of logger to start of plugin_startup since logging is used within the method.
  • Loading branch information
heifner committed Sep 16, 2019
1 parent 3b7b7bc commit e796f37
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3022,6 +3022,8 @@ namespace eosio {
}

void net_plugin::plugin_startup() {
handle_sighup();
try {
my->producer_plug = app().find_plugin<producer_plugin>();

// currently thread_pool only used for server_ioc
Expand Down Expand Up @@ -3056,17 +3058,13 @@ namespace eosio {
}
}

my->keepalive_timer.reset( new boost::asio::steady_timer( my->thread_pool->get_executor() ) );
my->ticker();

if( my->acceptor ) {
my->acceptor->open(my->listen_endpoint.protocol());
my->acceptor->set_option(tcp::acceptor::reuse_address(true));
try {
my->acceptor->bind(my->listen_endpoint);
} catch (const std::exception& e) {
fc_elog( logger, "net_plugin::plugin_startup failed to bind to port ${port}",
("port", my->listen_endpoint.port()));
elog( "net_plugin::plugin_startup failed to bind to port ${port}", ("port", my->listen_endpoint.port()));
throw e;
}
my->acceptor->listen();
Expand All @@ -3078,6 +3076,9 @@ namespace eosio {
cc.accepted_block.connect( boost::bind(&net_plugin_impl::accepted_block, my.get(), _1));
}

my->keepalive_timer.reset( new boost::asio::steady_timer( my->thread_pool->get_executor() ) );
my->ticker();

my->incoming_transaction_ack_subscription = app().get_channel<channels::transaction_ack>().subscribe(boost::bind(&net_plugin_impl::transaction_ack, my.get(), _1));

if( cc.get_read_mode() == chain::db_read_mode::READ_ONLY ) {
Expand All @@ -3090,7 +3091,12 @@ namespace eosio {
for( auto seed_node : my->supplied_peers ) {
connect( seed_node );
}
handle_sighup();

} catch (...) {
// always want plugin_shutdown even on exception
plugin_shutdown();
throw;
}
}

void net_plugin::handle_sighup() {
Expand Down

0 comments on commit e796f37

Please sign in to comment.