From 77b7cb03e94446e787d00f0adbe498d9b6907cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Sat, 3 Feb 2024 09:17:11 +0100 Subject: [PATCH] fix: maintenance mode should assume disable if db call fails. (#6120) Usually maintenance mode is disabled. If the call throws, which we see a lot of when a unleash instance is in terminating state, we should return a default value. By having it throw inside of the memoizee function, the response is not cached, and it will trigger new calls until it return a cachable result. --- .../maintenance/maintenance-service.ts | 21 +++++++++++-------- src/lib/services/version-service.ts | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/lib/features/maintenance/maintenance-service.ts b/src/lib/features/maintenance/maintenance-service.ts index 5e2fa6c881..a60267b426 100644 --- a/src/lib/features/maintenance/maintenance-service.ts +++ b/src/lib/features/maintenance/maintenance-service.ts @@ -33,19 +33,22 @@ export default class MaintenanceService implements IMaintenanceStatus { } async isMaintenanceMode(): Promise { - return ( - this.config.flagResolver.isEnabled('maintenanceMode') || - (await this.resolveMaintenance()) - ); + try { + return ( + this.config.flagResolver.isEnabled('maintenanceMode') || + (await this.resolveMaintenance()) + ); + } catch (e) { + this.logger.warn('Error checking maintenance mode', e); + return false; + } } async getMaintenanceSetting(): Promise { this.logger.debug('getMaintenanceSetting called'); - return ( - (await this.settingService.get(maintenanceSettingsKey)) || { - enabled: false, - } - ); + return this.settingService.getWithDefault(maintenanceSettingsKey, { + enabled: false, + }); } async toggleMaintenanceMode( diff --git a/src/lib/services/version-service.ts b/src/lib/services/version-service.ts index 4cd56a2f6b..a966490ac6 100644 --- a/src/lib/services/version-service.ts +++ b/src/lib/services/version-service.ts @@ -193,7 +193,7 @@ export default class VersionService { )) ?? { id: undefined }; this.instanceId = id; } catch (err) { - this.logger.warn('Could not find instanceInfo'); + this.logger.warn('Could not find instanceInfo', err); } }