From 77c6186bdbdef688390022e125792399f152b325 Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Mon, 5 Aug 2024 18:15:42 -0500 Subject: [PATCH] fix: do not stop redis/mongo/mongoose until all other operations (servers/bree/custom handlers) have completely finished gracefully exiting --- index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 77b6d52..9cac4db 100644 --- a/index.js +++ b/index.js @@ -279,15 +279,23 @@ class Graceful { await Promise.all([ // servers this.stopServers(code), - // redisClients - this.stopRedisClients(code), - // mongooses - this.stopMongooses(code), // brees this.stopBrees(code), // custom handlers this.stopCustomHandlers(code) ]); + // + // don't stop redis/mongoose until all other operations have ended + // (a lot of time the server cleanup will release counters/limiters) + // (or the job scheduler or application-layer code will require DB connections) + // (and closing them early may also cause uncaught exceptions) + // + await Promise.all([ + // redisClients + this.stopRedisClients(code), + // mongooses + this.stopMongooses(code) + ]); this.config.logger.info('Gracefully exited', { code, ...(this.config.ignoreHook ? { [this.config.ignoreHook]: true } : {}),