From 4cd8ef877ac8bf768b5670750cc41d045fd496fb Mon Sep 17 00:00:00 2001 From: imaxouning Date: Thu, 6 Mar 2025 19:22:30 +0300 Subject: [PATCH 1/3] fix: terminate on signal - remove terminate connections on `SIGUSR1`, `SIGUSR2` - remove `process.exit(...)` in terminate connections - safe `process.exit(0)` in default `beforeTerminate` --- lib/constants.ts | 2 +- lib/core.ts | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/constants.ts b/lib/constants.ts index f11166b..e02aaa4 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -19,7 +19,7 @@ export const defaultDispatcherOptions: PDOptions = { healthcheckInterval: 5000, healthcheckTimeout: 700, suppressStatusLogs: false, - beforeTerminate: () => Promise.resolve(), + beforeTerminate: () => Promise.resolve().then(() => process.exit(0)), }; export const defaultExLogger: ExLogger = { diff --git a/lib/core.ts b/lib/core.ts index 2b82371..371b872 100644 --- a/lib/core.ts +++ b/lib/core.ts @@ -75,17 +75,13 @@ export function initDB({ beforeTerminate() .catch(() => {}) .then(() => db.terminate()) - .then(() => process.exit(0)) .catch((error: unknown) => { // eslint-disable-next-line no-console console.error(error); - process.exit(-1); }); }; process.on('SIGINT', terminate); - process.on('SIGUSR1', terminate); - process.on('SIGUSR2', terminate); const CoreBaseModel = getModel(); CoreBaseModel.db = db; From b65af7075190864d8f14796138ddb312f45c4258 Mon Sep 17 00:00:00 2001 From: imaxouning Date: Thu, 6 Mar 2025 19:36:51 +0300 Subject: [PATCH 2/3] feat: remove `process.exit` --- lib/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/constants.ts b/lib/constants.ts index e02aaa4..f11166b 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -19,7 +19,7 @@ export const defaultDispatcherOptions: PDOptions = { healthcheckInterval: 5000, healthcheckTimeout: 700, suppressStatusLogs: false, - beforeTerminate: () => Promise.resolve().then(() => process.exit(0)), + beforeTerminate: () => Promise.resolve(), }; export const defaultExLogger: ExLogger = { From ca41e7beaf5ca51afdfd57fa836036944725f5f4 Mon Sep 17 00:00:00 2001 From: imaxouning Date: Fri, 7 Mar 2025 13:08:33 +0300 Subject: [PATCH 3/3] feat: return terminate function from initDb --- lib/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core.ts b/lib/core.ts index 371b872..5a34bae 100644 --- a/lib/core.ts +++ b/lib/core.ts @@ -118,5 +118,5 @@ export function initDB({ }, }; logger.info('Core-db is up and running!'); - return {db, CoreBaseModel, helpers}; + return {db, terminate, CoreBaseModel, helpers}; }