Log warning on mismatched slave or plugin versions

Log warning to the master log if a slave connects with a missmatched
version, missmatched plugins or missmatched plugin versions.
This commit is contained in:
Hornwitser committed 2023-02-21 19:35:35 +01:00
1 parent 17e4b088f1
commit 5426d9b2bd
3 files changed
+37 -3

No files matched your search

+2 -2
View File
@@ -45,8 +45,8 @@ class Master {
constructor(clusterLogger, pluginInfos, configPath, config) {
this.clusterLogger = clusterLogger;
/**
* Mapping of plugin name to info objects for known plugins
* @type {Map<string, Object>}
* Array of plugin info objects for known plugins
* @type {Array<object>}
*/
this.pluginInfos = pluginInfos;
this.configPath = configPath;
+25
View File
@@ -23,6 +23,7 @@ class SlaveConnection extends BaseConnection {
this._name = registerData.name;
this._version = registerData.version;
this.plugins = new Map(Object.entries(registerData.plugins));
this._checkPluginVersions();
this._master.slaves.set(this._id, {
agent: this._agent,
@@ -57,6 +58,30 @@ class SlaveConnection extends BaseConnection {
});
}
_checkPluginVersions() {
let pluginInfos = new Map(this._master.pluginInfos.map(i => [i.name, i]));
for (let [name, version] of this.plugins) {
let info = pluginInfos.get(name);
if (!info) {
logger.warn(`Slave ${this._name} has plugin ${name} ${version} which the master does not have`);
continue;
}
if (info.version !== version) {
logger.warn(
`Slave ${this._name} has plugin ${name} ${version} which does not match the version of this ` +
`plugin on the master (${info.version})`
);
}
}
for (let [name, info] of pluginInfos) {
if (!this.plugins.has(name)) {
logger.warn(`Slave ${this._name} is missing plugin ${name} ${info.version}`);
}
}
}
/**
* ID of the slave this connection is connected to
*
+10 -1
View File
@@ -269,7 +269,16 @@ ${err.stack}`
await connection.disconnect(1008, "Registered from another connection");
}
logger.verbose(`WsServer | registered slave ${data.id} version ${data.version}`);
logger.info(
`WsServer | registered slave ${data.name} (${data.id}) using agent ${data.agent} ${data.version}`
);
if (data.agent === "Clusterio Slave" && data.version !== packageVersion) {
logger.warn(
`Slave ${data.name} (${data.id}) connected using version ${data.version} which does not match ` +
`the version of the master is currently running (${packageVersion}). It may not work as expected.`
);
}
connection = new SlaveConnection(data, connector, this.master);
connector.on("close", () => {
if (this.slaveConnections.get(data.id) === connection) {