Skip to content

Commit

Permalink
Merge pull request #949 from AntelopeIO/GH-842-plugin-startup
Browse files Browse the repository at this point in the history
HTTP: plugin_startup throw on listener error
  • Loading branch information
heifner authored Oct 21, 2024
2 parents 2ea376d + 5f501b1 commit 96c6a32
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
14 changes: 8 additions & 6 deletions plugins/http_plugin/http_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,11 @@ namespace eosio {
}

void http_plugin::plugin_startup() {
app().executor().post(appbase::priority::high, [this] ()
{
// The reason we post here is because we want blockchain replay to happen before we start listening.
// post here because *_api_plugins that register api handlers depend on http_plugin. Since they depend on the
// http_plugin, this plugin_startup is called before any *_api_plugin::plugin_startup. The post avoid situation
// where the application is running and accepting http requests, but it doesn't have the request api handler
// registered yet.
app().executor().post(appbase::priority::high, exec_queue::read_write, [this]() {
try {
my->plugin_state->thread_pool.start( my->plugin_state->thread_pool_size, [](const fc::exception& e) {
fc_elog( logger(), "Exception in http thread pool, exiting: ${e}", ("e", e.to_detail_string()) );
Expand All @@ -493,13 +495,13 @@ namespace eosio {
my->listening.store(true);
} catch(fc::exception& e) {
fc_elog(logger(), "http_plugin startup fails for ${e}", ("e", e.to_detail_string()));
app().quit();
throw; // allow application exec() to exit with error
} catch(std::exception& e) {
fc_elog(logger(), "http_plugin startup fails for ${e}", ("e", e.what()));
app().quit();
throw; // allow application exec() to exit with error
} catch (...) {
fc_elog(logger(), "http_plugin startup fails, shutting down");
app().quit();
throw; // allow application exec() to exit with error
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace eosio {
static std::string get_server_header();

APPBASE_PLUGIN_REQUIRES()

void set_program_options(options_description&, options_description& cfg) override;

void plugin_initialize(const variables_map& options);
Expand Down
2 changes: 1 addition & 1 deletion plugins/http_plugin/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_executable( http_plugin_unit_tests ${UNIT_TESTS})

target_link_libraries( http_plugin_unit_tests
PRIVATE appbase
PRIVATE http_plugin
PRIVATE http_plugin
Boost::included_unit_test_framework ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )

target_include_directories( http_plugin_unit_tests PUBLIC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include <boost/test/unit_test.hpp>
#include <eosio/testing/tester.hpp>
#include <eosio/http_plugin/http_plugin.hpp>

using namespace eosio;
using namespace eosio::chain;
using namespace eosio::testing;

template<typename T>
auto call_parse_no_params(const string& body)
Expand All @@ -24,7 +22,7 @@ auto call_parse_possible_no_params(const string& body)
return parse_params<T, http_params_types::possible_no_params>(body);
}

BOOST_AUTO_TEST_SUITE(plugin_tests)
BOOST_AUTO_TEST_SUITE(http_plugin_tests)

BOOST_AUTO_TEST_CASE( make_trimmed_string_view ) try {
{ // empty string
Expand Down
4 changes: 1 addition & 3 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ target_include_directories( unit_test PUBLIC
${CMAKE_BINARY_DIR}/contracts
${CMAKE_CURRENT_SOURCE_DIR}/contracts
${CMAKE_CURRENT_BINARY_DIR}/contracts
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_SOURCE_DIR}/plugins/http_plugin/include
${CMAKE_SOURCE_DIR}/plugins/chain_interface/include)
${CMAKE_CURRENT_BINARY_DIR}/include)

### MARK TEST SUITES FOR EXECUTION ###
add_test(NAME protocol_feature_digest_unit_test COMMAND unit_test --run_test=protocol_feature_digest_tests --report_level=detailed --color_output)
Expand Down

0 comments on commit 96c6a32

Please sign in to comment.