mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 15:24:52 +09:00
Set status to unknown on slave disconnect
Change the instance status to unknown if the slave it's connected to is disconnected rather than leaving them at their previous state indefinitely.
This commit is contained in:
1 parent
c9ae964eee
commit
c59267d5ee
3 files changed
+21
-2
No files matched your search
@@ -256,6 +256,7 @@ class BaseMasterPlugin {
|
||||
* or received notice from a slave that the status of an instance has
|
||||
* changed. The possible statuses that can be notified about are:
|
||||
* - `unassigned:`: Instance is no longer asssigned to a slave.
|
||||
* - `unknown`: Slave assigned to instance is offline.
|
||||
* - `stopped`: Instance is no longer running or was just assigned to a
|
||||
* slave.
|
||||
* - `starting`: Instance is in the process of starting up.
|
||||
@@ -270,7 +271,8 @@ class BaseMasterPlugin {
|
||||
* they are assigned to a slave, when the slave then connects to the
|
||||
* master and informs of the current status of its instances this hook
|
||||
* is invoked for all those instances. You can detect this situation by
|
||||
* checking if prev equals `unknown`.
|
||||
* checking if prev equals `unknown`. If the slave disconnects the
|
||||
* instances will again get the `unknown` status.
|
||||
*
|
||||
* When instances are created on the master they will notify of a status
|
||||
* change with prev set to null. While the status of new instances is
|
||||
|
||||
@@ -39,6 +39,20 @@ class SlaveConnection extends BaseConnection {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.connector.on("close", () => {
|
||||
// Update status to unknown for instances on this slave.
|
||||
for (let instance of this._master.instances.values()) {
|
||||
if (instance.config.get("instance.assigned_slave") !== this._id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let prev = instance.status;
|
||||
instance.status = "unknown";
|
||||
this._master.instanceUpdated(instance);
|
||||
libPlugin.invokeHook(this._master.plugins, "onInstanceStatusChanged", instance, prev);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -88,6 +88,9 @@ describe("Integration of Clusterio", function() {
|
||||
slaveProcess = await spawn(
|
||||
"alt-slave:", `node ../../packages/slave run --config ${config}`, /Started slave/
|
||||
);
|
||||
// Add instance to test the unknown status afterwards
|
||||
await execCtl("instance create alt-test --id 99");
|
||||
await execCtl("instance assign alt-test 5");
|
||||
} finally {
|
||||
if (slaveProcess) {
|
||||
slaveProcess.kill("SIGINT");
|
||||
@@ -524,7 +527,7 @@ describe("Integration of Clusterio", function() {
|
||||
describe("instanceUpdateEventHandler()", function() {
|
||||
it("should have triggered for the previous instance status updates", function() {
|
||||
let statusesToCheck = new Set([
|
||||
"unassigned", "stopped", "creating_save", "exporting_data",
|
||||
"unassigned", "unknown", "stopped", "creating_save", "exporting_data",
|
||||
"starting", "running", "stopping", "deleted",
|
||||
]);
|
||||
let statusesNotSeen = new Set(statusesToCheck);
|
||||
|
||||
Reference in new issue
Block a user