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 #9065 from EOSIO/cleos-keods-race-2.0
Browse files Browse the repository at this point in the history
Fix for cleos and keosd race condition
  • Loading branch information
revl authored May 8, 2020
2 parents d2505e4 + 70f852d commit d8a7583
Showing 1 changed file with 78 additions and 73 deletions.
151 changes: 78 additions & 73 deletions plugins/http_plugin/http_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ namespace eosio {
else
cfg.add_options()
("unix-socket-path", bpo::value<string>(),
"The filename (relative to data-dir) to create a unix socket for HTTP RPC; set blank to disable.");
"The filename (relative to data-dir) to create a unix socket for HTTP RPC; set blank to disable.");
#endif

if(current_http_plugin_defaults.default_http_port)
Expand Down Expand Up @@ -783,86 +783,91 @@ namespace eosio {
void http_plugin::plugin_startup() {

handle_sighup(); // setup logging

my->thread_pool.emplace( "http", my->thread_pool_size );

if(my->listen_endpoint) {
app().post(appbase::priority::high, [this] ()
{
try {
my->create_server_for_endpoint(*my->listen_endpoint, my->server);
my->thread_pool.emplace( "http", my->thread_pool_size );
if(my->listen_endpoint) {
try {
my->create_server_for_endpoint(*my->listen_endpoint, my->server);

fc_ilog( logger, "start listening for http requests" );
my->server.listen(*my->listen_endpoint);
my->server.start_accept();
} catch ( const fc::exception& e ){
fc_elog( logger, "http service failed to start: ${e}", ("e", e.to_detail_string()) );
throw;
} catch ( const std::exception& e ){
fc_elog( logger, "http service failed to start: ${e}", ("e", e.what()) );
throw;
} catch (...) {
fc_elog( logger, "error thrown from http io service" );
throw;
}
}
fc_ilog( logger, "start listening for http requests" );
my->server.listen(*my->listen_endpoint);
my->server.start_accept();
} catch ( const fc::exception& e ){
fc_elog( logger, "http service failed to start: ${e}", ("e", e.to_detail_string()) );
throw;
} catch ( const std::exception& e ){
fc_elog( logger, "http service failed to start: ${e}", ("e", e.what()) );
throw;
} catch (...) {
fc_elog( logger, "error thrown from http io service" );
throw;
}
}

#ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS
if(my->unix_endpoint) {
try {
my->unix_server.clear_access_channels(websocketpp::log::alevel::all);
my->unix_server.init_asio( &my->thread_pool->get_executor() );
my->unix_server.set_max_http_body_size(my->max_body_size);
my->unix_server.listen(*my->unix_endpoint);
my->unix_server.set_http_handler([&, &ioc = my->thread_pool->get_executor()](connection_hdl hdl) {
my->handle_http_request<detail::asio_local_with_stub_log>( my->unix_server.get_con_from_hdl(hdl));
});
my->unix_server.start_accept();
} catch ( const fc::exception& e ){
fc_elog( logger, "unix socket service (${path}) failed to start: ${e}", ("e", e.to_detail_string())("path",my->unix_endpoint->path()) );
throw;
} catch ( const std::exception& e ){
fc_elog( logger, "unix socket service (${path}) failed to start: ${e}", ("e", e.what())("path",my->unix_endpoint->path()) );
throw;
} catch (...) {
fc_elog( logger, "error thrown from unix socket (${path}) io service", ("path",my->unix_endpoint->path()) );
throw;
}
}
if(my->unix_endpoint) {
try {
my->unix_server.clear_access_channels(websocketpp::log::alevel::all);
my->unix_server.init_asio( &my->thread_pool->get_executor() );
my->unix_server.set_max_http_body_size(my->max_body_size);
my->unix_server.listen(*my->unix_endpoint);
my->unix_server.set_http_handler([&, &ioc = my->thread_pool->get_executor()](connection_hdl hdl) {
my->handle_http_request<detail::asio_local_with_stub_log>( my->unix_server.get_con_from_hdl(hdl));
});
my->unix_server.start_accept();
} catch ( const fc::exception& e ){
fc_elog( logger, "unix socket service (${path}) failed to start: ${e}", ("e", e.to_detail_string())("path",my->unix_endpoint->path()) );
throw;
} catch ( const std::exception& e ){
fc_elog( logger, "unix socket service (${path}) failed to start: ${e}", ("e", e.what())("path",my->unix_endpoint->path()) );
throw;
} catch (...) {
fc_elog( logger, "error thrown from unix socket (${path}) io service", ("path",my->unix_endpoint->path()) );
throw;
}
}
#endif
if(my->https_listen_endpoint) {
try {
my->create_server_for_endpoint(*my->https_listen_endpoint, my->https_server);
my->https_server.set_tls_init_handler([this](websocketpp::connection_hdl hdl) -> ssl_context_ptr{
return my->on_tls_init(hdl);
});

fc_ilog( logger, "start listening for https requests" );
my->https_server.listen(*my->https_listen_endpoint);
my->https_server.start_accept();
} catch ( const fc::exception& e ){
fc_elog( logger, "https service failed to start: ${e}", ("e", e.to_detail_string()) );
throw;
} catch ( const std::exception& e ){
fc_elog( logger, "https service failed to start: ${e}", ("e", e.what()) );
throw;
} catch (...) {
fc_elog( logger, "error thrown from https io service" );
throw;
}
}

if(my->https_listen_endpoint) {
try {
my->create_server_for_endpoint(*my->https_listen_endpoint, my->https_server);
my->https_server.set_tls_init_handler([this](websocketpp::connection_hdl hdl) -> ssl_context_ptr{
return my->on_tls_init(hdl);
});

fc_ilog( logger, "start listening for https requests" );
my->https_server.listen(*my->https_listen_endpoint);
my->https_server.start_accept();
} catch ( const fc::exception& e ){
fc_elog( logger, "https service failed to start: ${e}", ("e", e.to_detail_string()) );
throw;
} catch ( const std::exception& e ){
fc_elog( logger, "https service failed to start: ${e}", ("e", e.what()) );
throw;
add_api({{
std::string("/v1/node/get_supported_apis"),
[&](string, string body, url_response_callback cb) mutable {
try {
if (body.empty()) body = "{}";
auto result = (*this).get_supported_apis();
cb(200, fc::variant(result));
} catch (...) {
handle_exception("node", "get_supported_apis", body, cb);
}
}
}});
} catch (...) {
fc_elog( logger, "error thrown from https io service" );
throw;
}
}

add_api({{
std::string("/v1/node/get_supported_apis"),
[&](string, string body, url_response_callback cb) mutable {
try {
if (body.empty()) body = "{}";
auto result = (*this).get_supported_apis();
cb(200, fc::variant(result));
} catch (...) {
handle_exception("node", "get_supported_apis", body, cb);
}
fc_elog(logger, "http_plugin startup fails, shutting down");
app().shutdown();
}
}});
});
}

void http_plugin::handle_sighup() {
Expand Down

0 comments on commit d8a7583

Please sign in to comment.