mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
Fix instance auto start
Bypass the Link layer and invoke the handleInstanceStartRequest method directly on the Instance object during the host's instance auto start phase.
This commit is contained in:
1 parent
256b455315
commit
fc5701f243
5 files changed
+41
-3
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",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
- 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 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}`,
|
||||||
|
|||||||
@@ -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