diff --git a/backend/server.js b/backend/server.js index 1a6341b8..df3de9d4 100644 --- a/backend/server.js +++ b/backend/server.js @@ -196,10 +196,4 @@ server.on("error", (err) => { process.on("uncaughtException", (err) => { console.error("Uncaught Exception:", err); process.exit(1); -}); - -// Handle unhandled promise rejections -process.on("unhandledRejection", (reason, promise) => { - console.error("Unhandled Rejection at:", promise, "reason:", reason); - process.exit(1); }); \ No newline at end of file diff --git a/backend/tests/unhandledRejection.policy.unit.test.js b/backend/tests/unhandledRejection.policy.unit.test.js new file mode 100644 index 00000000..2eef436f --- /dev/null +++ b/backend/tests/unhandledRejection.policy.unit.test.js @@ -0,0 +1,27 @@ +import { describe, it, expect } from "vitest"; +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; + +// --------------------------------------------------------------------------- +// unhandledRejection policy fix (issue #1441): two contradictory global +// listeners existed — the first logs and continues, the second called +// process.exit(1), so any unhandled rejection killed the whole server. +// Exactly one log-and-continue policy must remain. +// --------------------------------------------------------------------------- + +const serverSource = readFileSync(resolve(__dirname, "../server.js"), "utf8"); + +describe("server.js unhandledRejection policy", () => { + it("registers exactly one unhandledRejection listener", () => { + const matches = serverSource.match(/process\.on\(\s*["']unhandledRejection["']/g) || []; + expect(matches.length).toBe(1); + }); + + it("does not exit the process from the unhandledRejection handler", () => { + const listenerBlock = serverSource.slice( + serverSource.indexOf('"unhandledRejection"'), + serverSource.indexOf("unhandledRejection") + 300 + ); + expect(listenerBlock).not.toMatch(/process\.exit/); + }); +});