-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drain io_context after shutdown of plugins #34
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change doesn't seem sufficient for me; I wrote a small appbase test case yesterday, one moment while I post it
Yeah, my nodeos test is still failing in ci/cd. It was working locally for me. |
It is overkill on threads and stuff. But just run and ctrl-C, and it will fail, where imo this should not. Use your imagination that #include <appbase/application.hpp>
#include <iostream>
namespace bpo = boost::program_options;
using bpo::options_description;
using bpo::variables_map;
static bool thing = true;
struct thing_better_be_alive {
~thing_better_be_alive() {
if(!thing)
throw "BOOM";
}
};
class thready_plugin : public appbase::plugin<thready_plugin> {
public:
APPBASE_PLUGIN_REQUIRES();
void set_program_options( options_description& cli, options_description& cfg ) override {}
void thread_work() {
boost::asio::post(ctx, [&]() {
thing_better_be_alive better_be;
boost::asio::post(appbase::app().get_io_service(), [&,is_it=std::move(better_be)]() {
thread_work();
});
});
}
void plugin_initialize( const variables_map& options ) {}
void plugin_startup() {
for(unsigned i = 0; i < 48*4; i++)
thread_work();
for(unsigned i = 0; i < 48; ++i)
threads.emplace_back([this]() {
ctx.run();
});
}
void plugin_shutdown() {
usleep(100000); //oh gee it takes a while to stop
ctx.stop();
for(unsigned i = 0; i < 48; ++i)
threads[i].join();
}
~thready_plugin() {
thing = false;
}
boost::asio::io_context ctx;
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> wg = boost::asio::make_work_guard(ctx);
private:
std::vector<std::thread> threads;
};
int main(int argc, char** argv) {
appbase::application::register_plugin<thready_plugin>();
appbase::scoped_app app;
if( !app->initialize<thready_plugin>( argc, argv ) )
return -1;
app->startup();
app->exec();
return 0;
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm were you planning to bring it out of draft after more testing?
@@ -0,0 +1,79 @@ | |||
#include <appbase/application.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You added this file as a test but didn't plumb it through cmake etc. not sure if that's intentional or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/CMakeFiles.txt
has file(GLOB UNIT_TESTS "*.cpp")
I verified it runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely missed the glob 👍
application_base.cpp
Outdated
@@ -152,8 +152,8 @@ void application_base::wait_for_signal(std::shared_ptr<boost::asio::signal_set> | |||
}); | |||
} | |||
|
|||
void application_base::setup_signal_handling_on_ios(boost::asio::io_service& ios, bool startup) { | |||
std::shared_ptr<boost::asio::signal_set> ss = std::make_shared<boost::asio::signal_set>(ios, SIGINT, SIGTERM); | |||
void application_base::setup_signal_handling_on_ios(boost::asio::io_context& io_ctx, bool startup) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're touching everything to rename io_service
->io_context
, maybe might as well rename setup_signal_handling_on_ios
to setup_signal_handling_on_ioc
or such, since ios
meant io_service 🤷♂️
This solves the problem of hang on shutdown of nodeos. See AntelopeIO/spring#822.
Make sure to clear to the
io_context
after shutdown of the plugins. Also it usesstopped()
ofio_context
instead of the applicationis_quiting()
to avoid exiting the loop early.Example failure: https://github.com/AntelopeIO/spring/actions/runs/11075714563
Example with this PR: https://github.com/AntelopeIO/spring/actions/runs/11076069453
Needs AntelopeIO/spring#842