mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
Fix slave crashing when Factorio server is not executable
Handle errors events emitted from the child process created by lib/factorio/server and translate this error if it's EACCES.
This commit is contained in:
1 parent
0341d41165
commit
5e01f427af
1 file changed
+29
-8
@@ -699,6 +699,16 @@ class FactorioServer extends events.EventEmitter {
|
|||||||
this._server.stderr.pipe(stderr);
|
this._server.stderr.pipe(stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_resetState() {
|
||||||
|
this._state = "init";
|
||||||
|
this._server = null;
|
||||||
|
this._rconClient = null;
|
||||||
|
this._rconReady = false;
|
||||||
|
this._gameReady = false;
|
||||||
|
this._unexpected = [];
|
||||||
|
this._runningAutosave = null;
|
||||||
|
}
|
||||||
|
|
||||||
_watchExit() {
|
_watchExit() {
|
||||||
this._server.on("exit", (code, signal) => {
|
this._server.on("exit", (code, signal) => {
|
||||||
if (this._state !== "stopping") {
|
if (this._state !== "stopping") {
|
||||||
@@ -736,15 +746,21 @@ class FactorioServer extends events.EventEmitter {
|
|||||||
this._rconClient.end().catch(() => {});
|
this._rconClient.end().catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset server state
|
this._resetState();
|
||||||
this._state = "init";
|
this.emit("exit");
|
||||||
this._server = null;
|
});
|
||||||
this._rconClient = null;
|
this._server.on("error", err => {
|
||||||
this._rconReady = false;
|
if (err.code === "EACCES") {
|
||||||
this._gameReady = false;
|
this.emit("error", new libErrors.EnvironmentError("Unable to run server: Permission denied"));
|
||||||
this._unexpected = [];
|
} else {
|
||||||
this._runningAutosave = null;
|
this.emit("error", new libErrors.EnvironmentError(`Unexpected error:\n${err.stack}`));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._rconClient) {
|
||||||
|
this._rconClient.end().catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
this._resetState();
|
||||||
this.emit("exit");
|
this.emit("exit");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -805,6 +821,11 @@ class FactorioServer extends events.EventEmitter {
|
|||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
throw new Error(`Factorio exited with status ${code}`);
|
throw new Error(`Factorio exited with status ${code}`);
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code === "EACCES") {
|
||||||
|
throw new libErrors.EnvironmentError("Unable to run server: Permission denied");
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
this._state = "init";
|
this._state = "init";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user