Skip to content

Commit

Permalink
Add reason field to restart logs
Browse files Browse the repository at this point in the history
  • Loading branch information
d-gubert committed Nov 10, 2024
1 parent 7d6647f commit 653da28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/server/runtime/deno/AppsEngineDenoRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"');
Expand Down
11 changes: 8 additions & 3 deletions src/server/runtime/deno/LivenessManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand Down

0 comments on commit 653da28

Please sign in to comment.