0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-03-31 23:11:33 +02:00

construct: Redirect error propagation and startup failure.

This commit is contained in:
Jason Volk 2020-05-09 22:59:21 -07:00
parent 554478da49
commit ca18ea1c17
2 changed files with 12 additions and 3 deletions
construct
ircd

View file

@ -186,12 +186,13 @@ noexcept try
// different contexts.
ircd::ctx::latch start(2), quit(2);
std::exception_ptr eptr;
bool rethrow {false};
// Setup the matrix homeserver application. This will be executed on an
// ircd::context (dedicated stack). We construct several objects on the
// stack which are the basis for our matrix homeserver. When the stack
// unwinds, the homeserver will go out of service.
const auto homeserver{[&origin, &server_name, &start, &quit, &eptr]
const auto homeserver{[&origin, &server_name, &start, &quit, &eptr, &rethrow]
{
try
{
@ -213,6 +214,8 @@ noexcept try
}
};
rethrow = true;
// 7 Notify the loader the homeserver is ready for service.
start.count_down_and_wait();
@ -247,7 +250,7 @@ noexcept try
// to start and stop the homeserver.
const ircd::run::changed loader
{
[&homeserver, &start, &quit, &eptr](const auto &level)
[&homeserver, &start, &quit, &eptr, &rethrow](const auto &level)
{
static ircd::context context;
@ -264,8 +267,10 @@ noexcept try
// 8 Check if error on start; rethrowing that here propagates
// to ircd::main() and triggers a runlevel QUIT sequence.
if(!!eptr)
if(!!eptr && rethrow)
std::rethrow_exception(eptr);
else if(!!eptr)
ircd::quit();
// 8.1
return;

View file

@ -291,6 +291,7 @@ noexcept try
// When this function is entered IRCd will transition to START indicating
// that subsystems are initializing.
run::set(run::level::START);
ctx::interruption_point();
// These objects are the init()'s and fini()'s for each subsystem.
// Appearing here ties their life to the main context. Initialization can
@ -312,13 +313,16 @@ noexcept try
{
ircd::run::set(run::level::QUIT);
}};
ctx::interruption_point();
// IRCd will now transition to the LOAD state allowing library user's to
// load their applications using the run::changed callback.
run::set(run::level::LOAD);
ctx::interruption_point();
// IRCd will now transition to the RUN state indicating full functionality.
run::set(run::level::RUN);
ctx::interruption_point();
// This call blocks until the main context is notified or interrupted etc.
// Waiting here will hold open this stack with all of the above objects