From 665e865c7a61480c9758bd820d7d6dd7c78f9384 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Thu, 29 Mar 2018 14:28:50 -0400 Subject: [PATCH] When a plugin throws during startup, cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some of our plugins will throw an exception on startup. For example, the http or net plugin will throw if it can’t bind to an address. Exceptions thrown at this stage are uncaught and cause the process to exit. However, in the process of unwinding the stack to exit, application’s dtor will call all of the already started plugins dtors. Some of these plugins don’t handle the case where their dtor is called without shtudown() being called on the plugin first. Result can be a (benign, but still embarrassing) crash on exit. Change appbase so that any exception thrown during startup() is caught, then all plugins shutdown, then exception is rethrown so that the app continues to exit. --- application.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/application.cpp b/application.cpp index 04771c561..4b493aaaf 100644 --- a/application.cpp +++ b/application.cpp @@ -57,8 +57,13 @@ bfs::path application::get_logging_conf() const { } void application::startup() { - for (auto plugin : initialized_plugins) - plugin->startup(); + try { + for (auto plugin : initialized_plugins) + plugin->startup(); + } catch(...) { + shutdown(); + throw; + } } application& application::instance() {