Skip to content

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

Description

@chirag127

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:

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions