Skip to content

Commit

Permalink
fix: do not stop redis/mongo/mongoose until all other operations (ser…
Browse files Browse the repository at this point in the history
…vers/bree/custom handlers) have completely finished gracefully exiting
  • Loading branch information
titanism committed Aug 5, 2024
1 parent ac7d456 commit 77c6186
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } : {}),
Expand Down

0 comments on commit 77c6186

Please sign in to comment.