AntelopeIO / appbase

Other
1 stars 6 forks source link

Ensure that `plugin_shutdown()` is always called. #26

Closed greg7mdp closed 1 year ago

greg7mdp commented 1 year ago

Even if there was an exception during plugin_startup().

Resolves AntelopeIO/leap#25.

Currently, because a plugin is stored in the running_plugins list only after plugin_startup(), it would not be present if it throws during plugin_startup(), and as a consequence plugin_shutdown() would not be called on this plugin.

We need to make sure that plugin_shutdown() is called regardless of whether plugin_startup() completed successfully or not. That way, plugins can rest assured that whatever thread_pool or timer they started during plugin_startup() will be cleaned up, and no lambda referencing the plugin will be executed after the plugin is destroyed by the framework.

The fix is just flipping two lines in abstract_plugin::startup(). The rest is just adding a test to verify that the fix indeed works.

see parent issue https://github.com/AntelopeIO/spring/issues/842.