Merge remote-tracking branch 'upstream/master' into fix/instance-config-change-crash

This commit is contained in:
bbassie committed 2026-09-13 17:09:02 +00:00
commit 767f9e7fe3
16 files changed
+410 -27

No files matched your search

+19 -4
View File
@@ -48,12 +48,16 @@ export default class ControlConnection extends BaseConnection {
this._version = registerData.version;
this.connector.on("connect", () => {
this.connector._socket!.clusterio_ignore_dump = Boolean(this.ws_dumper);
});
// A resume installs a fresh socket, so re-apply the ignore flag or the
// dumper's own frames get echoed back into it and recurse forever.
for (let event of ["connect", "resume"] as const) {
this.connector.on(event, () => {
this.connector._socket!.clusterio_ignore_dump = Boolean(this.ws_dumper);
});
}
this.connector.on("close", () => {
if (this.logTransport) {
logger.remove(this.logTransport);
this._controller.clusterLogger.remove(this.logTransport);
this.logTransport = null;
}
if (this.ws_dumper) {
@@ -288,6 +292,9 @@ export default class ControlConnection extends BaseConnection {
}
async handleInstanceCreateRequest(request: lib.InstanceCreateRequest) {
if ((request.config["instance.assigned_host"] ?? null) !== null) {
throw new lib.RequestError("instance.assigned_host must be set through the assign-host interface");
}
const instanceConfig = new lib.InstanceConfig("controller");
if (request.cloneFromId) {
const baseInstance = this._controller.instances.get(request.cloneFromId);
@@ -1070,6 +1077,11 @@ export default class ControlConnection extends BaseConnection {
}
this._controller.users.deleteUser(user);
for (let controlConnection of this._controller.wsServer.controlConnections.values()) {
if (controlConnection.user.id === user.id) {
controlConnection.connector.terminate();
}
}
if (user.isAdmin) {
this._controller.sendTo("allInstances", new lib.InstanceAdminlistUpdateEvent(name, false));
@@ -1325,6 +1337,9 @@ export default class ControlConnection extends BaseConnection {
}
async handleDebugDumpWsRequest(request: lib.DebugDumpWsRequest) {
if (this.ws_dumper) {
return; // Already dumping
}
this.ws_dumper = data => {
if (this.connector.connected) {
this.send(new lib.DebugWsMessageEvent(data.direction, data.content));
+11 -3
View File
@@ -208,9 +208,17 @@ export default class InstanceManager {
instance.config.set("instance.assigned_host", hostId);
if (newHostConnection) {
await newHostConnection.send(
new lib.InstanceAssignInternalRequest(instanceId, instance.config.toRemote("host")),
);
try {
await newHostConnection.send(
new lib.InstanceAssignInternalRequest(instanceId, instance.config.toRemote("host")),
);
} catch (err) {
// Leave unassigned so the assign can be retried
instance.config.set("instance.assigned_host", null);
instance.status = "unassigned";
this.records.set(instance);
throw err;
}
} else {
instance.status = "unassigned";
}
+3 -1
View File
@@ -119,7 +119,9 @@ export default class UserManager {
roles.add(defaultRoleId);
}
const user = new User(this.records, this._controllerRoles, 0, name, roles);
// Reject tokens issued before the user existed, e.g. for a previous user by the same name
const tokenValidAfter = Math.floor(Date.now() / 1000);
const user = new User(this.records, this._controllerRoles, tokenValidAfter, name, roles);
this.records.set(user);
return user;
}
+14 -4
View File
@@ -310,7 +310,12 @@ export default class Instance extends lib.Link {
return;
}
let name = /^([^ ]+)/.exec(parsed.message)![1];
// Guard against lines that classify as actions but lack a name
let nameMatch = /^([^ ]+)/.exec(parsed.message);
if (!nameMatch) {
return;
}
let name = nameMatch[1];
// Detect player leave and join
if (parsed.action === "JOIN") {
@@ -326,7 +331,9 @@ export default class Instance extends lib.Link {
// Detect banned and admin state change, whitelist changes are not logged
if (parsed.action === "BAN") {
const reason = /\. Reason: (.+)\.$/.exec(parsed.message)![1];
// Ban lines without a ". Reason: X." tail default to no reason
const reasonMatch = /\. Reason: (.+)\.$/.exec(parsed.message);
const reason = reasonMatch ? reasonMatch[1] : "";
this._recordUserUpdate(parsed.action, name, reason !== "unspecified" ? reason : "");
} else if (["UNBANNED", "PROMOTE", "DEMOTE"].includes(parsed.action)) {
this._recordUserUpdate(parsed.action as "UNBANNED" | "PROMOTE" | "DEMOTE", name);
@@ -352,8 +359,11 @@ export default class Instance extends lib.Link {
return;
}
const name = /^([^ ]+)/.exec(parsed.message)![1];
this._recordUserUpdate(parsed.action as "PROMOTE" | "DEMOTE", name);
const nameMatch = /^([^ ]+)/.exec(parsed.message);
if (!nameMatch) {
return;
}
this._recordUserUpdate(parsed.action as "PROMOTE" | "DEMOTE", nameMatch[1]);
});
}
+3 -1
View File
@@ -2,6 +2,7 @@ import { Type, Static } from "@sinclair/typebox";
import UserDetails, { IUser } from "./UserDetails.js";
import { StringEnum, jsonArray, plainJson } from "./composites.js";
import { MessageRequest } from "./messages_core.js";
import { PermissionError } from "../errors.js";
export class UserGetRequest {
declare ["constructor"]: typeof UserGetRequest;
@@ -276,8 +277,9 @@ export class UserBulkImportRequest {
user.checkPermission("core.user.set_whitelisted");
break;
default:
// Unvalidated input during permission check: deny, don't throw a bare Error
// @ts-expect-error Unreachable
throw new Error(`Unknown import / restore type: ${data.importType}`);
throw new PermissionError(`Unknown import / restore type: ${data.importType}`);
}
}
}
+11 -7
View File
@@ -196,16 +196,20 @@ export class Link {
let entry = this._validateMessage(message);
if (entry && this.connector.dst.type === libData.Address.control) {
let permissionMessage = message as libData.MessageRequest | libData.MessageEvent;
try {
this.validatePermission(
message as libData.MessageRequest | libData.MessageEvent,
entry
); // Somewhat hacky, defined in ControlConnection
this.validatePermission(permissionMessage, entry); // Somewhat hacky, defined in ControlConnection
} catch (err) {
if (err instanceof libErrors.PermissionError) {
return;
// A non-PermissionError means the permission check itself is
// broken. validatePermission (control connections only) already
// sent a response error, so log and drop instead of crashing.
if (!(err instanceof libErrors.PermissionError)) {
logger.error(
`Unexpected error checking permission for ${permissionMessage.name}:\n` +
`${(err as Error).stack ?? (err as Error).message}`
);
}
throw err;
return;
}
}
@@ -44,7 +44,7 @@ export default function LoadScenarioModal(props: LoadScenarioModalProps) {
}
if (values.mapSettings && values.mapSettings.trim()) {
try {
mapSettings = JSON.parse(values.mapGenSettings);
mapSettings = JSON.parse(values.mapSettings);
} catch (err: any) {
form.setFields([{ name: "mapSettings", errors: [err.message] }]);
return;
@@ -146,6 +146,13 @@ export default function UserViewPage() {
new lib.UserDeleteRequest(userName)
).then(() => {
navigate("/users");
}, err => {
if (err instanceof lib.SessionLost && userName === account.name) {
// Got kicked out after deleting our own account
navigate("/users");
return;
}
throw err;
}).catch(notifyErrorHandler("Error deleting user"));
}}
>