From 072cf1c72f4cd2564d29bec95e73f2924f72a670 Mon Sep 17 00:00:00 2001 From: danilo neves cruz Date: Tue, 26 Nov 2024 12:20:09 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20server:=20fix=20graceful=20shutd?= =?UTF-8?q?own?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/index.ts b/server/index.ts index 997d2185..a3e10281 100644 --- a/server/index.ts +++ b/server/index.ts @@ -57,12 +57,18 @@ app.onError((error, c) => { return c.text(error instanceof Error ? error.message : String(error), 500); }); -serve(app); +const server = serve(app); ["SIGINT", "SIGTERM"].map((code) => - process.on(code, () => { - Promise.allSettled([close(), closeAndFlush()]).catch(() => undefined); - }), + process.on(code, () => + server.close((error) => { + Promise.allSettled([close(), closeAndFlush()]) + .then((results) => { + process.exit(error || results.some((result) => result.status === "rejected") ? 1 : 0); // eslint-disable-line n/no-process-exit + }) + .catch(() => undefined); + }), + ), ); declare module "hono" {