#660·pull

Unawaited disconnectMongoDB() + redisClient.quit() in SIGINT/SIGTERM handler race Deno.exit(0)

Author: chirag127Created Jul 4, 2026Updated Jul 4, 2026

Problem

handleAppTermination in src/index.ts is a sync function that fires Deno.exit(0) before Mongo disconnect and Redis quit complete, so the shutdown log is misleading and connections may not close cleanly.

Cite

src/index.ts:56-67:

typescript
function handleAppTermination(signal: string) {
  log.info(`[${signal}] Signal received: closing MongoDB connection`);
  disconnectMongoDB();          // async, returns Promise, not awaited
  try {
    redisClient.quit();         // ioredis quit() returns Promise, not awaited
  } catch { }
  log.info("[MongoDB] Connection closed due to app termination");
  Deno.exit(0);                 // fires before either finishes
}

src/configs/database.ts:15 declares export const disconnectMongoDB = async () => { await mongoose.disconnect(); ... }.

Expected

Process awaits both disconnects before exit, matching src/worker.ts:44-52 gracefulShutdown which correctly does await worker.close() + await redisClient.quit().

Actual

On SIGTERM, Deno.exit(0) runs synchronously; unawaited Promises are dropped mid-flight. "Connection closed" log prints before disconnect actually happens.

Env

Repo master @ 2026-04-13, deno.json version 2.0.0-alpha.4, mongoose ^8.8.1, ioredis ^5.4.1, Deno 2.

Thanks for maintaining wei/pull!