Skip to content

Commit

Permalink
chore: add reason to app restart log (#34878)
Browse files Browse the repository at this point in the history
Co-authored-by: Douglas Gubert <[email protected]>
  • Loading branch information
dionisio-bot[bot] and d-gubert authored Jan 3, 2025
1 parent 2a004b3 commit c51de29
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/apps-engine/src/server/runtime/deno/LivenessManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,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;
}

Expand All @@ -162,7 +162,7 @@ export class LivenessManager {

private handleError(err: Error) {
this.debug('App has failed to start.`', err);
this.restartProcess();
this.restartProcess(err.message);
}

private handleExit(exitCode: number, signal: string) {
Expand All @@ -174,24 +174,29 @@ 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 async restartProcess() {
private async restartProcess(reason: string) {
if (this.restartCount >= this.options.maxRestarts) {
this.debug('Limit of restarts reached (%d). Aborting restart...', this.options.maxRestarts);
this.controller.stopApp();
return;
}

this.restartLog.push({
reason,
restartedAt: new Date(),
source: 'liveness-manager',
pid: this.subprocess.pid,
Expand Down

0 comments on commit c51de29

Please sign in to comment.