Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7925 from EOSIO/fix-crash-port-1.8
Browse files Browse the repository at this point in the history
Fix intermittent crash on exit when port already in use - 1.8
  • Loading branch information
heifner authored Sep 16, 2019
2 parents 856f4b9 + e122844 commit c4da348
Show file tree
Hide file tree
Showing 2 changed files with 18 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
6 changes: 6 additions & 0 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ void producer_plugin::plugin_startup()
{ try {
handle_sighup(); // Sets loggers

try {
ilog("producer plugin: plugin_startup() begin");

chain::controller& chain = my->chain_plug->chain();
Expand Down Expand Up @@ -840,6 +841,11 @@ void producer_plugin::plugin_startup()
my->schedule_production_loop();

ilog("producer plugin: plugin_startup() end");
} catch( ... ) {
// always call plugin_shutdown, even on exception
plugin_shutdown();
throw;
}
} FC_CAPTURE_AND_RETHROW() }

void producer_plugin::plugin_shutdown() {
Expand Down

0 comments on commit c4da348

Please sign in to comment.