Fix host hang on stopping during create save

If during the startup of an instance the Factorio server is started up
to create a new save and the host shutdown in initiated then the
instance will be commanded to stop while the FactorioServer state is
"create".  This was was not handled by Instance.stop leaving the
child_process running after the host is done shutting down.

Kill the FactorioServer on stop if the current state of it is stopping
or create to make sure the server actually stops.
This commit is contained in:
Hornwitser committed 2024-01-23 16:18:21 +01:00
1 parent 96bd5fb1c2
commit 256b455315
3 files changed
+10 -2

No files matched your search

+1
View File
@@ -15,6 +15,7 @@
- Fixed installer incorrectly claiming the options --factorio-dir and --no-download-headless conflicts with each other.
- Fixed a memory leak on every request sent over the WebSocket.
- Fixed assertion error on closing or invalidating a link with messages forwarded from a virtual link.
- Fixed host hanging if stopped while an instance is in the process of creating a save during startup.
## Version 2.0.0-alpha.14
+5
View File
@@ -955,6 +955,11 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
await lib.invokeHook(this.plugins, "onStop");
await this.server.stop();
await this.sendSaveListUpdate();
} else if (
this.server._state === "stopping"
|| this.server._state === "create"
) {
await this.server.kill();
}
}
+4 -2
View File
@@ -865,7 +865,9 @@ export class FactorioServer extends events.EventEmitter {
try {
let [code, signal] = await events.once(this._server, "exit");
void signal;
if (signal) {
throw new Error(`Factorio exited with signal ${signal}`);
}
if (code !== 0) {
throw new Error(`Factorio exited with status ${code}`);
}
@@ -1092,7 +1094,7 @@ export class FactorioServer extends events.EventEmitter {
* process.
*/
async kill(unexpected = false) {
this._check(["running", "stopping"]);
this._check(["running", "stopping", "create"]);
this._killed = true;
if (!unexpected) {
this._state = "stopping";