From 56aae782871a677f0de8aaaea2bed201ab50de17 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 30 Jan 2023 11:14:29 -0300 Subject: [PATCH] Chore: Improve service's licence check (#27872) --- apps/meteor/ee/server/lib/EnterpriseCheck.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/meteor/ee/server/lib/EnterpriseCheck.ts b/apps/meteor/ee/server/lib/EnterpriseCheck.ts index 2cfb42d4d93..8bccfed5907 100644 --- a/apps/meteor/ee/server/lib/EnterpriseCheck.ts +++ b/apps/meteor/ee/server/lib/EnterpriseCheck.ts @@ -18,7 +18,7 @@ export const EnterpriseCheck: ServiceSchema = { const services: { name: string; nodes: string[]; - }[] = await this.broker.call('$node.services'); + }[] = await this.broker.call('$node.services', { skipInternal: true }); const currentService = services.find((service) => { return service.name === this.name; @@ -33,16 +33,21 @@ export const EnterpriseCheck: ServiceSchema = { const firstNode = nodes.sort().shift(); - // if the first node is the current node and there are others nodes running the same service, then it should shutdown - return firstNode === this.broker.nodeID && nodes.length > 0; + // if the first node is the current node and there are others nodes running the same service or + // if this is the only one node online, then we should shutdown + return firstNode === this.broker.nodeID && (nodes.length > 0 || services.length === 1); }, }, async started(): Promise { setInterval(async () => { - const hasLicense = await this.broker.call('license.hasLicense', ['scalability']); - if (hasLicense) { - checkFails = 0; - return; + try { + const hasLicense = await this.broker.call('license.hasLicense', ['scalability']); + if (hasLicense) { + checkFails = 0; + return; + } + } catch (e: unknown) { + // check failed, so continue } if (++checkFails < maxFails) {