From 5c3b6b90887be697fad6bf7fb067bab6f8a0e127 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 11 Nov 2024 17:59:09 -0300 Subject: [PATCH] chore: add reason to app restart log (#33930) --- .../src/server/runtime/deno/LivenessManager.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/apps-engine/src/server/runtime/deno/LivenessManager.ts b/packages/apps-engine/src/server/runtime/deno/LivenessManager.ts index dc89acc8718b..2450b3f2ad50 100644 --- a/packages/apps-engine/src/server/runtime/deno/LivenessManager.ts +++ b/packages/apps-engine/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,