Fix plugin shutdown not called on bad startup

During startup the plugins are loaded one by one and init is called for
each of them.  But due to the already loaded plugins being discarded if
one of the plugins throw an error an unclean shutdown that might hang
on timers started by plugins occurs.  This leads to the master server
starting up, printing an error, displaying the shutdown sequence and
then hang forever.

Fix by storing the plugins loaded into masterPlugins as they are loaded
instead only after all of them have been loaded.
This commit is contained in:
Hornwitser committed 2021-03-07 15:18:39 +01:00
1 parent a17e9295e7
commit e1c7d35ce4
1 file changed
+2 -4
+2 -4
View File
@@ -1693,7 +1693,6 @@ ${err.stack}`
});
async function loadPlugins() {
let plugins = new Map();
for (let pluginInfo of pluginInfos) {
if (!masterConfig.group(pluginInfo.name).get("load_plugin")) {
continue;
@@ -1712,7 +1711,7 @@ async function loadPlugins() {
pluginInfo, { app, config: masterConfig, db, slaveConnections }, { endpointHitCounter }, logger
);
await masterPlugin.init();
plugins.set(pluginInfo.name, masterPlugin);
masterPlugins.set(pluginInfo.name, masterPlugin);
} catch (err) {
throw new libErrors.PluginError(pluginInfo.name, err);
@@ -1720,13 +1719,12 @@ async function loadPlugins() {
logger.info(`Loaded plugin ${pluginInfo.name} in ${Date.now() - pluginLoadStarted}ms`);
}
return plugins;
}
// handle plugins on the master
async function pluginManagement() {
let startPluginLoad = Date.now();
masterPlugins = await loadPlugins();
await loadPlugins();
logger.info(`All plugins loaded in ${Date.now() - startPluginLoad}ms`);
}