Wait for a start in progress before stopping an instance

A stop request sent while the instance was starting ran alongside the
start. During save preparation it did nothing and the instance came up
running anyway. Once Factorio was launched it put the server into the
stopping state, the start then failed with "Expected state running but
state is stopping" and its cleanup killed the server mid shutdown.

Stop and restart requests now wait for any start, stop or save in
progress to finish first, then stop the instance if it is running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-29 22:52:09 +00:00
1 parent fa2883d74e
commit eb1e2e2a5e
3 files changed
+74 -2

No files matched your search

+22
View File
@@ -474,4 +474,26 @@ describe("start-all and stop-all commands", function() {
assert.equal(await getInstanceStatus(testInstId3), "stopped");
});
});
describe("stop while starting", function() {
it("stops the instance once it has started", async function() {
this.timeout(30000);
const control = getControl();
const started = control.sendTo({ instanceId: testInstId1 }, new lib.InstanceStartRequest());
// Unroutable until the host has connected the instance
for (;;) {
try {
await control.sendTo({ instanceId: testInstId1 }, new lib.InstanceStopRequest());
break;
} catch (err) {
if (!(err instanceof lib.UnavailableError)) {
throw err;
}
await lib.wait(10);
}
}
await started;
assert.equal(await getInstanceStatus(testInstId1), "stopped");
});
});
});