From 4db641fdf02a46789d2e4e0aa47eee34c5378a8f Mon Sep 17 00:00:00 2001 From: Essem Date: Wed, 7 Jan 2026 20:23:35 -0600 Subject: [PATCH] fix: Handle SIGTERM in media API --- src/api/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 7af377d4..8019b2ad 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -316,13 +316,14 @@ function stopHTTPServer() { } let stopping = false; -process.on("SIGINT", () => { + +function sigHandler(signal: NodeJS.Signals) { if (stopping) { - logger.info("Another SIGINT detected, forcing shutdown..."); + logger.info(`Another ${signal} detected, forcing shutdown...`); process.exit(); } stopping = true; - logger.info("SIGINT detected, finishing jobs and shutting down..."); + logger.info(`${signal} detected, finishing jobs and shutting down...`); httpServer.removeAllListeners("upgrade"); const closeResponse = Buffer.concat([Buffer.from([Rclose])]); for (const client of wss.clients) { @@ -344,7 +345,10 @@ process.on("SIGINT", () => { stopHTTPServer(); } }); -}); +} + +process.on("SIGINT", (s) => sigHandler(s)); +process.on("SIGTERM", (s) => sigHandler(s)); const allowedExtensions = ["gif", "png", "jpeg", "jpg", "webp", "avif"]; const fileSize = 10485760; -- 2.51.2