mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 16:13:12 +09:00
Add SIGKILL detection to lib/factorio/server
Check if Factorio terminated as a result of SIGKILL and throw an error suggesting the system may be low on memory as a cause. Also print exit code if the unexpected shutdown occured without a signal.
This commit is contained in:
1 parent
7a2abaa5db
commit
554cab4fb0
3 files changed
+51
-1
No files matched your search
@@ -12,9 +12,13 @@ class InvalidMessage extends Error { }
|
|||||||
// Errror class for known errors occuring during startup
|
// Errror class for known errors occuring during startup
|
||||||
class StartupError extends Error { }
|
class StartupError extends Error { }
|
||||||
|
|
||||||
|
// Errors outside of our control.
|
||||||
|
class EnvironmentError extends Error { }
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
CommandError,
|
CommandError,
|
||||||
RequestError,
|
RequestError,
|
||||||
InvalidMessage,
|
InvalidMessage,
|
||||||
StartupError,
|
StartupError,
|
||||||
|
EnvironmentError,
|
||||||
}
|
}
|
||||||
+17
-1
@@ -14,6 +14,8 @@ const crypto = require("crypto");
|
|||||||
|
|
||||||
const ini = require("ini");
|
const ini = require("ini");
|
||||||
const rconClient = require("rcon-client");
|
const rconClient = require("rcon-client");
|
||||||
|
const errors = require("lib/errors");
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the version of Factorio the datadir is pointing to by
|
* Determines the version of Factorio the datadir is pointing to by
|
||||||
@@ -461,7 +463,21 @@ class FactorioServer extends events.EventEmitter {
|
|||||||
this._server.on('exit', (code, signal) => {
|
this._server.on('exit', (code, signal) => {
|
||||||
if (this._state !== "stopping") {
|
if (this._state !== "stopping") {
|
||||||
if (this._unexpected.length === 0) {
|
if (this._unexpected.length === 0) {
|
||||||
this.emit('error', new Error("Factorio server unexpectedly shut down"));
|
if (signal === 'SIGKILL') {
|
||||||
|
this.emit('error', new errors.EnvironmentError(
|
||||||
|
"Factorio server was unexpectedly killed, is the system low on memory?"
|
||||||
|
));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
let msg;
|
||||||
|
if (code !== null) {
|
||||||
|
msg = `Factorio server unexpectedly shut down with code ${code}`
|
||||||
|
} else {
|
||||||
|
msg = `Factorio server was unexpectedly shut by down by signal ${signal}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emit('error', new Error(msg));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (this._unexpected.length === 1) {
|
} else if (this._unexpected.length === 1) {
|
||||||
this.emit('error', new Error(this._unexpected[0]));
|
this.emit('error', new Error(this._unexpected[0]));
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const fs = require("fs-extra");
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
const factorio = require("lib/factorio");
|
const factorio = require("lib/factorio");
|
||||||
|
const errors = require("lib/errors");
|
||||||
|
|
||||||
|
|
||||||
describe("Integration of lib/factorio/server", function() {
|
describe("Integration of lib/factorio/server", function() {
|
||||||
@@ -182,5 +183,34 @@ describe("Integration of lib/factorio/server", function() {
|
|||||||
await server.stop();
|
await server.stop();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe(".start() termination detection", function() {
|
||||||
|
it("should tell if Factorio got killed", async function() {
|
||||||
|
// This does not work on Windows
|
||||||
|
if (process.platform == "win32") {
|
||||||
|
this.skip();
|
||||||
|
}
|
||||||
|
slowTest(this);
|
||||||
|
log(".start() for kill detection");
|
||||||
|
|
||||||
|
let startPromise = server.start("test.zip");
|
||||||
|
server.once('output', () => server._server.kill('SIGKILL'));
|
||||||
|
|
||||||
|
await assert.rejects(
|
||||||
|
startPromise,
|
||||||
|
new errors.EnvironmentError("Factorio server was unexpectedly killed, is the system low on memory?")
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should tell if Factorio unexpectedly closed with a code", async function() {
|
||||||
|
slowTest(this);
|
||||||
|
log(".start() for unexpected close detection");
|
||||||
|
|
||||||
|
await assert.rejects(
|
||||||
|
server.start("does-not-exist.zip"),
|
||||||
|
new errors.EnvironmentError("Factorio server unexpectedly shut down with code 1")
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user