From 6196ee7ccf63183c92ae54cae26d9b37bcb3876f Mon Sep 17 00:00:00 2001 From: SaelixCode Date: Tue, 3 Mar 2026 19:36:08 -0500 Subject: [PATCH] feat: enhance container crash detection by extracting exit codes and filtering intentional stops --- backend/src/services/MonitorService.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/src/services/MonitorService.ts b/backend/src/services/MonitorService.ts index 0634932f..d076267c 100644 --- a/backend/src/services/MonitorService.ts +++ b/backend/src/services/MonitorService.ts @@ -126,10 +126,19 @@ export class MonitorService { // Usually, users will restart or remove the container. // To prevent massive spam, we check if it exited in the last 30 secs if (c.State === 'exited') { - // Find when it exited, this might need an inspect, but we can do a naive check if it's recent - // The status string says something like "Exited (1) 5 minutes ago" + // Check if it exited recently if (c.Status.includes('seconds ago')) { - await notifier.dispatchAlert('error', `Container Crash Detected: ${c.Names[0]} has exited recently.`); + // Extract the exit code from the status string (e.g., "Exited (143) 5 seconds ago") + const match = c.Status.match(/Exited \((\d+)\)/i); + const exitCode = match ? parseInt(match[1], 10) : null; + + // 0: Success, 137: SIGKILL (Force Stop), 143: SIGTERM (Graceful Stop), 255: Docker Daemon Stop + const intentionalExitCodes = [0, 137, 143, 255]; + + // Only alert if we found a code AND it is not an intentional stop + if (exitCode !== null && !intentionalExitCodes.includes(exitCode)) { + await notifier.dispatchAlert('error', `Container Crash Detected: ${c.Names[0]} exited unexpectedly (Code: ${exitCode}).`); + } } } else if (String(c.Status).includes('unhealthy')) { await notifier.dispatchAlert('error', `Healthcheck Failed: Container ${c.Names[0]} is unhealthy.`);