Skip to content

Commit

Permalink
fix(cluster): improve null safety
Browse files Browse the repository at this point in the history
Closes #308
  • Loading branch information
mKeRix committed Oct 20, 2020
1 parent e2daef5 commit c02269c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cluster/cluster.service.ts
Expand Up @@ -24,7 +24,8 @@ try {
}

@Injectable()
export class ClusterService extends Democracy
export class ClusterService
extends Democracy
implements OnModuleInit, OnApplicationBootstrap, OnApplicationShutdown {
private readonly configService: ConfigService;
private readonly config: ClusterConfig;
Expand Down Expand Up @@ -119,7 +120,7 @@ export class ClusterService extends Democracy
*/
quorumReached(): boolean {
const activeNodes = Object.values(this.nodes()).filter(
(node) => node.state !== 'removed'
(node) => node?.state !== 'removed'
);
return !this.config.quorum || activeNodes.length >= this.config.quorum;
}
Expand Down Expand Up @@ -162,7 +163,7 @@ export class ClusterService extends Democracy

if (!data.chunk && data.state === 'leader') {
const leaders = Object.entries(this._nodes).filter(
(node) => node[1].state === 'leader'
(node) => node[1]?.state === 'leader'
);

if (leaders.length > 1) {
Expand Down

0 comments on commit c02269c

Please sign in to comment.