Don't try stopping if instance is already stopped (#401)

Ignore stop if instance status is already stopped. Fixes instance status
getting stuck at stopping if Factorio exits during startup due to the
stopped status having already been sent at the time stop is invoked.

Fixes #400
This commit is contained in:
Hornwitser authored and GitHub committed 2021-08-03 16:08:16 +02:00
1 parent dbe623c9a7
commit f2c9cd0c62
2 files changed
+16 -6

No files matched your search

+5 -6
View File
@@ -168,8 +168,8 @@ class Instance extends libLink.Link {
maxConcurrentCommands: this.config.get("factorio.max_concurrent_commands"),
};
// Valid statuses are stopped, starting, running, stopping, creating_save and exporting_data.
this._status = "stopped";
this._running = false;
this._loadedSave = null;
this.server = new libFactorio.FactorioServer(
factorioDir, this._dir, serverOptions
@@ -276,7 +276,6 @@ class Instance extends libLink.Link {
}
notifyExit() {
this._running = false;
this._loadedSave = null;
this.notifyStatus("stopped");
@@ -577,7 +576,6 @@ class Instance extends libLink.Link {
await this.sendSaveListUpdate();
await libPlugin.invokeHook(this.plugins, "onStart");
this._running = true;
this.notifyStatus("running");
}
@@ -602,7 +600,6 @@ class Instance extends libLink.Link {
await libPlugin.invokeHook(this.plugins, "onStart");
this._running = true;
this.notifyStatus("running");
}
@@ -683,7 +680,9 @@ class Instance extends libLink.Link {
* Stop the instance
*/
async stop() {
this._running = false;
if (this._status === "stopped") {
return;
}
this.notifyStatus("stopping");
// XXX this needs more thought to it
@@ -703,7 +702,7 @@ class Instance extends libLink.Link {
async getMetricsRequestHandler() {
let results = [];
if (this._running) {
if (!["stopped", "stopping"].includes(this._status)) {
let pluginResults = await libPlugin.invokeHook(this.plugins, "onMetrics");
for (let metricIterator of pluginResults) {
for await (let metric of metricIterator) {
+11
View File
@@ -253,6 +253,17 @@ describe("Integration of Clusterio", function() {
await execCtl("instance config set 44 factorio.version latest");
}
});
it("should not leave the instance in the stopping state if it fails", async function() {
slowTest(this);
try {
await execCtl("instance config set 44 factorio.game_port 100000");
await assert.rejects(execCtl("instance start test"));
await checkInstanceStatus(44, "stopped");
} finally {
await execCtl("instance config set 44 factorio.game_port");
}
});
it("starts the given save", async function() {
slowTest(this);
await execCtl("instance start test --save world.zip");