From 09e1141d321463a29d0c1f18f004da31ea2d4257 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Sun, 10 Nov 2024 15:43:37 -0300 Subject: [PATCH] Add reason field to restart logs --- src/server/runtime/deno/AppsEngineDenoRuntime.ts | 2 +- src/server/runtime/deno/LivenessManager.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/src/server/runtime/deno/AppsEngineDenoRuntime.ts index dd64cdacb..00c07aa8a 100644 --- a/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -271,7 +271,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter { // When an app has just been installed, the status in the storageItem passed to this controller will be "initialized" // So, whenever we get that value here, let's just make it 'auto_enabled' - let status = this.storageItem.status; + let { status } = this.storageItem; if (status === AppStatus.INITIALIZED) { logger.info('Stored status was "initialized". Changing to "auto_enabled"'); diff --git a/src/server/runtime/deno/LivenessManager.ts b/src/server/runtime/deno/LivenessManager.ts index dc89acc87..2450b3f2a 100644 --- a/src/server/runtime/deno/LivenessManager.ts +++ b/src/server/runtime/deno/LivenessManager.ts @@ -132,7 +132,7 @@ export class LivenessManager { if (reason === 'timeout' && this.pingTimeoutConsecutiveCount >= this.options.consecutiveTimeoutLimit) { this.debug('Subprocess failed to respond to pings %d consecutive times. Attempting restart...', this.options.consecutiveTimeoutLimit); - this.restartProcess(); + this.restartProcess('Too many pings timed out'); return false; } @@ -164,17 +164,21 @@ export class LivenessManager { return; } + let reason: string; + // Otherwise we try to restart the subprocess, if possible if (signal) { this.debug('App has been killed (%s). Attempting restart #%d...', signal, this.restartCount + 1); + reason = `App has been killed with signal ${signal}`; } else { this.debug('App has exited with code %d. Attempting restart #%d...', exitCode, this.restartCount + 1); + reason = `App has exited with code ${exitCode}`; } - this.restartProcess(); + this.restartProcess(reason); } - private restartProcess() { + private restartProcess(reason: string) { if (this.restartCount >= this.options.maxRestarts) { this.debug('Limit of restarts reached (%d). Aborting restart...', this.options.maxRestarts); this.controller.stopApp(); @@ -184,6 +188,7 @@ export class LivenessManager { this.pingTimeoutConsecutiveCount = 0; this.restartCount++; this.restartLog.push({ + reason, restartedAt: new Date(), source: 'liveness-manager', pid: this.subprocess.pid,