Commit 90a9c015 authored by Dominik Charousset's avatar Dominik Charousset

Extend registry lifetime over scheduler lifetime

parent 75be7f62
...@@ -283,20 +283,26 @@ void actor_registry::start() { ...@@ -283,20 +283,26 @@ void actor_registry::start() {
} }
void actor_registry::stop() { void actor_registry::stop() {
scoped_actor self{system_, true}; class dropping_execution_unit : public execution_unit {
try { public:
for (auto& kvp : named_entries_) { dropping_execution_unit(actor_system* sys) : execution_unit(sys) {
self->monitor(kvp.second);
self->send_exit(kvp.second, exit_reason::kill);
self->receive(
[](const down_msg&) {
// nop // nop
} }
); void exec_later(resumable*) override {
} // should not happen in the first place
CAF_LOG_ERROR("actor registry actor called exec_later during shutdown");
} }
catch (actor_exited&) { };
CAF_LOG_ERROR("actor_exited thrown in actor_registry::stop"); // the scheduler is already stopped -> invoke exit messages manually
dropping_execution_unit dummy{&system_};
for (auto& kvp : named_entries_) {
auto mp = mailbox_element::make_joint(invalid_actor_addr,
invalid_message_id,
{},
exit_msg{invalid_actor_addr,
exit_reason::kill});
auto ptr = static_cast<local_actor*>(actor_cast<abstract_actor*>(kvp.second));
ptr->exec_single_event(&dummy, mp);
} }
named_entries_.clear(); named_entries_.clear();
} }
......
...@@ -127,10 +127,10 @@ actor_system::actor_system(actor_system_config&& cfg) ...@@ -127,10 +127,10 @@ actor_system::actor_system(actor_system_config&& cfg)
node_.swap(cfg.network_id); node_.swap(cfg.network_id);
// fire up remaining modules // fire up remaining modules
logger_.start(); logger_.start();
registry_.start();
for (auto& mod : modules_) for (auto& mod : modules_)
if (mod) if (mod)
mod->start(); mod->start();
registry_.start();
// store config parameters in ConfigServ // store config parameters in ConfigServ
auto cs = registry_.get(atom("ConfigServ")); auto cs = registry_.get(atom("ConfigServ"));
anon_send(cs, put_atom::value, "middleman.enable-automatic-connections", anon_send(cs, put_atom::value, "middleman.enable-automatic-connections",
...@@ -141,10 +141,10 @@ actor_system::~actor_system() { ...@@ -141,10 +141,10 @@ actor_system::~actor_system() {
if (await_actors_before_shutdown_) if (await_actors_before_shutdown_)
await_all_actors_done(); await_all_actors_done();
// stop modules in reverse order // stop modules in reverse order
registry_.stop();
for (auto i = modules_.rbegin(); i != modules_.rend(); ++i) for (auto i = modules_.rbegin(); i != modules_.rend(); ++i)
if (*i) if (*i)
(*i)->stop(); (*i)->stop();
registry_.stop();
logger_.stop(); logger_.stop();
CAF_SET_LOGGER_SYS(nullptr); CAF_SET_LOGGER_SYS(nullptr);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment