mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 16:23:12 +09:00
Fix onExit not being invoked if plugin load fails
Fix instance not properly exiting if an error occurs during the loading of a plugin.
This commit is contained in:
1 parent
1beffb1bfd
commit
b8b8c44083
2 files changed
+22
-10
No files matched your search
+5
-1
@@ -73,7 +73,11 @@ class BaseInstancePlugin {
|
|||||||
async onStop() { }
|
async onStop() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the Factorio server exited
|
* Called when the instance exits
|
||||||
|
*
|
||||||
|
* Invoked when the instance is shut down. This may occur after init
|
||||||
|
* has been called if an error occurs during startup. Note that if
|
||||||
|
* the plugin's init() throws this method will still be invoked.
|
||||||
*/
|
*/
|
||||||
onExit() { }
|
onExit() { }
|
||||||
|
|
||||||
|
|||||||
@@ -129,6 +129,17 @@ class Instance extends link.Link{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _loadPlugin(pluginInfo, slave) {
|
||||||
|
let pluginLoadStarted = Date.now();
|
||||||
|
let { InstancePlugin } = require(`./plugins/${pluginInfo.name}/${pluginInfo.instanceEntrypoint}`);
|
||||||
|
let instancePlugin = new InstancePlugin(pluginInfo, this, slave);
|
||||||
|
this.plugins.set(pluginInfo.name, instancePlugin);
|
||||||
|
await instancePlugin.init();
|
||||||
|
plugin.attachPluginMessages(this, pluginInfo, instancePlugin);
|
||||||
|
|
||||||
|
console.log(`Clusterio | Loaded plugin ${pluginInfo.name} in ${Date.now() - pluginLoadStarted}ms`);
|
||||||
|
}
|
||||||
|
|
||||||
async init(pluginInfos, masterPlugins, slave) {
|
async init(pluginInfos, masterPlugins, slave) {
|
||||||
await this.server.init();
|
await this.server.init();
|
||||||
|
|
||||||
@@ -142,15 +153,12 @@ class Instance extends link.Link{
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// require plugin class and initialize it
|
try {
|
||||||
let pluginLoadStarted = Date.now();
|
await this._loadPlugin(pluginInfo, slave);
|
||||||
let { InstancePlugin } = require(`./plugins/${pluginInfo.name}/${pluginInfo.instanceEntrypoint}`);
|
} catch (err) {
|
||||||
let instancePlugin = new InstancePlugin(pluginInfo, this, slave);
|
this.notifyExit();
|
||||||
await instancePlugin.init();
|
throw err;
|
||||||
this.plugins.set(pluginInfo.name, instancePlugin);
|
}
|
||||||
plugin.attachPluginMessages(this, pluginInfo, instancePlugin);
|
|
||||||
|
|
||||||
console.log(`Clusterio | Loaded plugin ${pluginInfo.name} in ${Date.now() - pluginLoadStarted}ms`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user