mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 07:24:52 +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() { }
|
||||
|
||||
/**
|
||||
* 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() { }
|
||||
|
||||
|
||||
@@ -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) {
|
||||
await this.server.init();
|
||||
|
||||
@@ -142,15 +153,12 @@ class Instance extends link.Link{
|
||||
continue;
|
||||
}
|
||||
|
||||
// require plugin class and initialize it
|
||||
let pluginLoadStarted = Date.now();
|
||||
let { InstancePlugin } = require(`./plugins/${pluginInfo.name}/${pluginInfo.instanceEntrypoint}`);
|
||||
let instancePlugin = new InstancePlugin(pluginInfo, this, slave);
|
||||
await instancePlugin.init();
|
||||
this.plugins.set(pluginInfo.name, instancePlugin);
|
||||
plugin.attachPluginMessages(this, pluginInfo, instancePlugin);
|
||||
|
||||
console.log(`Clusterio | Loaded plugin ${pluginInfo.name} in ${Date.now() - pluginLoadStarted}ms`);
|
||||
try {
|
||||
await this._loadPlugin(pluginInfo, slave);
|
||||
} catch (err) {
|
||||
this.notifyExit();
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user