Skip to content

Commit

Permalink
fix(cluster): prevent complete removal of configured peers
Browse files Browse the repository at this point in the history
All peers that are configured manually will just perpetually stick
around in removed state now.
  • Loading branch information
mKeRix committed Feb 17, 2020
1 parent e028414 commit 87d74c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/cluster/cluster.service.ts
Expand Up @@ -111,6 +111,22 @@ export class ClusterService extends Democracy
});
}

protected checkBallots(candidate: string): this {
super.checkBallots(candidate);

// if the peer address was configured manually it should not be removed completely
const node = this._nodes[candidate];
if (this.config.peerAddresses.includes(node.source)) {
this.logger.debug(
`Saving configured peer ${node.source} from ultimate removal`
);
clearTimeout(node.disconnected);
delete node.disconnected;
}

return this;
}

protected startBonjourDiscovery(): void {
this.advertisement = mdns.createAdvertisement(
mdns.udp('room-assistant'),
Expand Down
5 changes: 5 additions & 0 deletions typings/democracy/index.d.ts
@@ -1,14 +1,18 @@
declare module 'democracy' {
import {Socket} from 'dgram';
import Timeout = NodeJS.Timeout;

export default class Democracy {
protected options: InternalOptions;
protected socket: Socket;
protected _nodes: {[key: string]: Node};
protected _id: string;
protected _weight: number;
protected _state: 'leader' | 'citizen' | 'removed';

constructor(opts?: Options);
protected addNodeToList(node: Node): void;
protected checkBallots(candidate: string): this;
hello(): this;
nodes(): { [key: string]: Node };
leader(): Node;
Expand Down Expand Up @@ -50,5 +54,6 @@ declare module 'democracy' {
last: Date;
voters: string[];
channels: string[];
disconnected?: Timeout;
}
}

0 comments on commit 87d74c0

Please sign in to comment.