Skip to content

Graceful shutdown missing for unhandledRejection and uncaughtException #25

Description

@Sumith-Kumar-Saini

In server.js, runtime errors trigger process.exit(1) immediately, bypassing gracefulShutdown(). This can leave DB/Redis connections open.

Code Reference:
server.js lines 8-17:

process.on('unhandledRejection', ...);
process.on('uncaughtException', ...);

Both call process.exit(1) directly without leaving any room for graceful shutdown.

Expected Behaviour:
Runtime errors should trigger gracefulShutdown() to cleanly close the HTTP server, MongoDB and Redis connections before exiting.

Suggested Fix:
Wrap both error handlers to await gracefulShutdown() before termination:

process.on('unhandledRejection', async (...) => {
  logger.error(...);
  await gracefulShutdown();
});
process.on('uncaughtException', async (...) => {
  logger.error(...);
  await gracefulShutdown();
});

File Affected: server.js

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