From efd950bd9394975201655fefb8c47f0edb44d273 Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Sun, 9 Aug 2026 16:01:23 +0200 Subject: [PATCH] fix(server): log unhandled rejections instead of crashing the process Node 24 terminates the whole process on an unhandled promise rejection, so a single request's stray rejection could take the server down for every user (as the USER_STOPPED agent-abort bug did). Add a process-level unhandledRejection handler that logs and keeps serving. Uncaught exceptions are intentionally left on Node's default crash-and-restart, since process state is unsafe afterward. Claude-Session: https://claude.ai/code/session_01ULhhLQ24DvnYwzP4afDuye --- apps/server/src/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/server/src/index.ts b/apps/server/src/index.ts index 2aff6e7a3..3bf36d1b6 100644 --- a/apps/server/src/index.ts +++ b/apps/server/src/index.ts @@ -10,6 +10,14 @@ export { createApp } from "./http/app"; async function main() { await runStartupChecks(); + // Safety net: Node 24 crashes the whole process on an unhandled rejection. One request's + // stray promise must not take the server down for everyone, so log and keep serving. + // Registered after startup checks so a broken startup still fails loudly. (Left uncaught + // exceptions on Node's default crash-and-restart, since process state is unsafe after one.) + process.on("unhandledRejection", (reason) => { + console.error("[unhandledRejection]", reason); + }); + const port = process.env.NODE_ENV === "production" ? Number.parseInt(process.env.PORT ?? "3000", 10) : env.SERVER_PORT;