From 80af61d1183c221983907008ea9ec3610856cebf Mon Sep 17 00:00:00 2001 From: Ben Allfree Date: Thu, 22 Jun 2023 18:31:03 -0700 Subject: [PATCH] fix: maintenance mode timeout fixed --- .../InstanceService/InstanceService.ts | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/daemon/src/services/InstanceService/InstanceService.ts b/packages/daemon/src/services/InstanceService/InstanceService.ts index d3103220..b12f2c2c 100644 --- a/packages/daemon/src/services/InstanceService/InstanceService.ts +++ b/packages/daemon/src/services/InstanceService/InstanceService.ts @@ -94,9 +94,15 @@ export const instanceService = mkSingleton( retry(0) return } - if (instanceApi.status() === InstanceApiStatus.Healthy) { - dbg(`API found and healthy, returning`) - resolve(instanceApi) + try { + if (instanceApi.status() === InstanceApiStatus.Healthy) { + dbg(`API found and healthy, returning`) + resolve(instanceApi) + return + } + } catch (e) { + dbg(`Instance is in an error state, returning error`) + reject(e) return } dbg(`API found but not healthy, waiting`) @@ -144,8 +150,10 @@ export const instanceService = mkSingleton( /* Initialize API */ + let _shutdownReason: Error | undefined const api: InstanceApi = { status: () => { + if (_shutdownReason) throw _shutdownReason return status }, internalUrl: () => { @@ -166,18 +174,20 @@ export const instanceService = mkSingleton( }, shutdown: async (reason) => { if (reason) { + _shutdownReason = reason error(`Panic shutdown for ${reason}`) } else { dbg(`Graceful shutdown`) } - if (api.status() === InstanceApiStatus.ShuttingDown) { - throw new Error(`Already shutting down`) + if (status === InstanceApiStatus.ShuttingDown) { + warn(`Already shutting down`) + return } return shutdownManager.shutdown() }, } const _safeShutdown = async (reason?: Error) => { - if (api.status() === InstanceApiStatus.ShuttingDown) { + if (status === InstanceApiStatus.ShuttingDown) { warn(`Already shutting down, ${reason} will not be reported.`) return } @@ -186,7 +196,7 @@ export const instanceService = mkSingleton( instanceApis[id] = api const healthyGuard = () => { - if (api.status() !== InstanceApiStatus.ShuttingDown) return + if (status !== InstanceApiStatus.ShuttingDown) return throw new Error( `HealthyGuard detected instance is shutting down. Aborting further initialization.` )