mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-29 08:47:13 +09:00
Merge pull request #574 from Hornwitser/fix-auto-start
Fix instance auto start Fix host hang on stopping during create save
This commit is contained in:
7 files changed
+51
-5
No files matched your search
@@ -35,6 +35,7 @@ module.exports = {
|
|||||||
"rules": {
|
"rules": {
|
||||||
"prefer-arrow-callback": "off",
|
"prefer-arrow-callback": "off",
|
||||||
"no-invalid-this": "off",
|
"no-invalid-this": "off",
|
||||||
|
"valid-jsdoc": "off",
|
||||||
"node/no-unpublished-import": "off",
|
"node/no-unpublished-import": "off",
|
||||||
"node/no-unpublished-require": "off",
|
"node/no-unpublished-require": "off",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
- Fixed installer incorrectly claiming the options --factorio-dir and --no-download-headless conflicts with each other.
|
- 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 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 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.
|
||||||
|
- Fixed `instance.auto_start` option.
|
||||||
|
|
||||||
|
|
||||||
## Version 2.0.0-alpha.14
|
## Version 2.0.0-alpha.14
|
||||||
|
|||||||
@@ -268,7 +268,6 @@ If you want to use a different user for the command line interface, you can gene
|
|||||||
|
|
||||||
## Known Issues
|
## Known Issues
|
||||||
|
|
||||||
- The `instance.auto_start` option is currently is broken and will not work, turn it off and do not use it for now.
|
|
||||||
- When the `server_select` plugin is installed you may see `[error] Unhandled event server_select:UpdateInstancesEvent` logged when starting an instance.
|
- When the `server_select` plugin is installed you may see `[error] Unhandled event server_select:UpdateInstancesEvent` logged when starting an instance.
|
||||||
This should be ignored as it does not indicate an error occured.
|
This should be ignored as it does not indicate an error occured.
|
||||||
- After migrating from Alpha 13 to Alpha 14 running an instance data export fails with the error `Upload failed: 401 Unauthorized` due to the host token being issued to a slave.
|
- After migrating from Alpha 13 to Alpha 14 running an instance data export fails with the error `Upload failed: 401 Unauthorized` due to the host token being issued to a slave.
|
||||||
|
|||||||
@@ -1056,7 +1056,7 @@ export default class Host extends lib.Link {
|
|||||||
if (instanceInfo.config.get("instance.auto_start")) {
|
if (instanceInfo.config.get("instance.auto_start")) {
|
||||||
try {
|
try {
|
||||||
let instanceConnection = await this._connectInstance(instanceId);
|
let instanceConnection = await this._connectInstance(instanceId);
|
||||||
await instanceConnection.send(new lib.InstanceStartRequest());
|
await instanceConnection.instance.handleInstanceStartRequest(new lib.InstanceStartRequest());
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`Error during auto startup for ${instanceInfo.config.get("instance.name")}:\n${err.stack}`,
|
`Error during auto startup for ${instanceInfo.config.get("instance.name")}:\n${err.stack}`,
|
||||||
|
|||||||
@@ -955,6 +955,11 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
await lib.invokeHook(this.plugins, "onStop");
|
await lib.invokeHook(this.plugins, "onStop");
|
||||||
await this.server.stop();
|
await this.server.stop();
|
||||||
await this.sendSaveListUpdate();
|
await this.sendSaveListUpdate();
|
||||||
|
} else if (
|
||||||
|
this.server._state === "stopping"
|
||||||
|
|| this.server._state === "create"
|
||||||
|
) {
|
||||||
|
await this.server.kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -865,7 +865,9 @@ export class FactorioServer extends events.EventEmitter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let [code, signal] = await events.once(this._server, "exit");
|
let [code, signal] = await events.once(this._server, "exit");
|
||||||
void signal;
|
if (signal) {
|
||||||
|
throw new Error(`Factorio exited with signal ${signal}`);
|
||||||
|
}
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
throw new Error(`Factorio exited with status ${code}`);
|
throw new Error(`Factorio exited with status ${code}`);
|
||||||
}
|
}
|
||||||
@@ -1092,7 +1094,7 @@ export class FactorioServer extends events.EventEmitter {
|
|||||||
* process.
|
* process.
|
||||||
*/
|
*/
|
||||||
async kill(unexpected = false) {
|
async kill(unexpected = false) {
|
||||||
this._check(["running", "stopping"]);
|
this._check(["running", "stopping", "create"]);
|
||||||
this._killed = true;
|
this._killed = true;
|
||||||
if (!unexpected) {
|
if (!unexpected) {
|
||||||
this._state = "stopping";
|
this._state = "stopping";
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const {
|
|||||||
} = require("./index");
|
} = require("./index");
|
||||||
|
|
||||||
|
|
||||||
|
/** @returns {Promise<Map<number, lib.InstanceDetails>>} */
|
||||||
async function getInstances() {
|
async function getInstances() {
|
||||||
let instances = await getControl().send(new lib.InstanceDetailsListRequest());
|
let instances = await getControl().send(new lib.InstanceDetailsListRequest());
|
||||||
return new Map(instances.map(instance => [instance.id, instance]));
|
return new Map(instances.map(instance => [instance.id, instance]));
|
||||||
@@ -27,6 +28,10 @@ async function checkInstanceStatus(id, status) {
|
|||||||
assert.equal(instances.get(44).status, status, "incorrect instance status");
|
assert.equal(instances.get(44).status, status, "incorrect instance status");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function spawnAltHost(config = "alt-host-config.json") {
|
||||||
|
return await spawn("alt-host:", `node ../../packages/host run --config ${config}`, /Started host/);
|
||||||
|
}
|
||||||
|
|
||||||
async function startAltHost() {
|
async function startAltHost() {
|
||||||
let config = "alt-host-config.json";
|
let config = "alt-host-config.json";
|
||||||
let configPath = path.join("temp", "test", config);
|
let configPath = path.join("temp", "test", config);
|
||||||
@@ -38,7 +43,7 @@ async function startAltHost() {
|
|||||||
await exec(`node ../../packages/host --config ${config} config set host.instances_directory alt-instances`);
|
await exec(`node ../../packages/host --config ${config} config set host.instances_directory alt-instances`);
|
||||||
await exec(`node ../../packages/host --config ${config} config set host.factorio_directory ../../factorio`);
|
await exec(`node ../../packages/host --config ${config} config set host.factorio_directory ../../factorio`);
|
||||||
await exec(`node ../../packages/host --config ${config} config set host.mods_directory alt-mods`);
|
await exec(`node ../../packages/host --config ${config} config set host.mods_directory alt-mods`);
|
||||||
return await spawn("alt-host:", `node ../../packages/host run --config ${config}`, /Started host/);
|
return await spawnAltHost(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function stopAltHost(hostProcess) {
|
async function stopAltHost(hostProcess) {
|
||||||
@@ -200,6 +205,38 @@ describe("Integration of Clusterio", function() {
|
|||||||
assert(await fs.pathExists(clusterioLib), "mod was not downloaded by the test");
|
assert(await fs.pathExists(clusterioLib), "mod was not downloaded by the test");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it("should auto start instances with auto_start enabled", async function() {
|
||||||
|
slowTest(this);
|
||||||
|
|
||||||
|
let hostProcess;
|
||||||
|
try {
|
||||||
|
hostProcess = await startAltHost();
|
||||||
|
await execCtl("instance create alt-start --id 97");
|
||||||
|
await execCtl("instance assign alt-start 5");
|
||||||
|
await execCtl("instance config set alt-start instance.auto_start true");
|
||||||
|
await stopAltHost(hostProcess);
|
||||||
|
hostProcess = await spawnAltHost();
|
||||||
|
// Stop the host immediatly to test the handling of stopping
|
||||||
|
// instances while automatically started and a save is being created
|
||||||
|
await stopAltHost(hostProcess);
|
||||||
|
hostProcess = await spawnAltHost();
|
||||||
|
let status;
|
||||||
|
// Wait for instance status to become running.
|
||||||
|
for (let i = 0; i < 100; i++) {
|
||||||
|
const instances = await getInstances();
|
||||||
|
status = instances.get(97)?.status ?? "not_present";
|
||||||
|
if (status === "running") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await wait(100); // Try again 10 times per second.
|
||||||
|
}
|
||||||
|
assert.equal(status, "running");
|
||||||
|
await execCtl("instance stop alt-start");
|
||||||
|
await execCtl("instance delete alt-start");
|
||||||
|
} finally {
|
||||||
|
await stopAltHost(hostProcess);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("clusterioctl", function() {
|
describe("clusterioctl", function() {
|
||||||
|
|||||||
Reference in new issue
Block a user