fix: maintenance mode timeout fixed

This commit is contained in:
Ben Allfree 2023-06-22 18:31:03 -07:00
parent 5c0a233067
commit 80af61d118

View File

@ -94,11 +94,17 @@ export const instanceService = mkSingleton(
retry(0) retry(0)
return return
} }
try {
if (instanceApi.status() === InstanceApiStatus.Healthy) { if (instanceApi.status() === InstanceApiStatus.Healthy) {
dbg(`API found and healthy, returning`) dbg(`API found and healthy, returning`)
resolve(instanceApi) resolve(instanceApi)
return return
} }
} catch (e) {
dbg(`Instance is in an error state, returning error`)
reject(e)
return
}
dbg(`API found but not healthy, waiting`) dbg(`API found but not healthy, waiting`)
retry() retry()
} }
@ -144,8 +150,10 @@ export const instanceService = mkSingleton(
/* /*
Initialize API Initialize API
*/ */
let _shutdownReason: Error | undefined
const api: InstanceApi = { const api: InstanceApi = {
status: () => { status: () => {
if (_shutdownReason) throw _shutdownReason
return status return status
}, },
internalUrl: () => { internalUrl: () => {
@ -166,18 +174,20 @@ export const instanceService = mkSingleton(
}, },
shutdown: async (reason) => { shutdown: async (reason) => {
if (reason) { if (reason) {
_shutdownReason = reason
error(`Panic shutdown for ${reason}`) error(`Panic shutdown for ${reason}`)
} else { } else {
dbg(`Graceful shutdown`) dbg(`Graceful shutdown`)
} }
if (api.status() === InstanceApiStatus.ShuttingDown) { if (status === InstanceApiStatus.ShuttingDown) {
throw new Error(`Already shutting down`) warn(`Already shutting down`)
return
} }
return shutdownManager.shutdown() return shutdownManager.shutdown()
}, },
} }
const _safeShutdown = async (reason?: Error) => { const _safeShutdown = async (reason?: Error) => {
if (api.status() === InstanceApiStatus.ShuttingDown) { if (status === InstanceApiStatus.ShuttingDown) {
warn(`Already shutting down, ${reason} will not be reported.`) warn(`Already shutting down, ${reason} will not be reported.`)
return return
} }
@ -186,7 +196,7 @@ export const instanceService = mkSingleton(
instanceApis[id] = api instanceApis[id] = api
const healthyGuard = () => { const healthyGuard = () => {
if (api.status() !== InstanceApiStatus.ShuttingDown) return if (status !== InstanceApiStatus.ShuttingDown) return
throw new Error( throw new Error(
`HealthyGuard detected instance is shutting down. Aborting further initialization.` `HealthyGuard detected instance is shutting down. Aborting further initialization.`
) )