Skip to content

fix: shutdown manager for handling cleanup tasks#8

Open
dhirajsuthar781 wants to merge 1 commit intorahulnikam2002:masterfrom
dhirajsuthar781:fix/shutdown-system
Open

fix: shutdown manager for handling cleanup tasks#8
dhirajsuthar781 wants to merge 1 commit intorahulnikam2002:masterfrom
dhirajsuthar781:fix/shutdown-system

Conversation

@dhirajsuthar781
Copy link
Copy Markdown

This PR introduces a centralized ShutdownManager to handle graceful shutdown of the application and all its resources (MongoDB, PostgreSQL, RabbitMQ, HTTP server).

Previously, shutdown logic was tightly coupled within the startServer() function, making it harder to scale, maintain, and extend. This refactor extracts that logic into a reusable, production-grade lifecycle component.

What’s Changed

config/shutdown.js

Responsibilities:

  • Register cleanup tasks dynamically
  • Listen to system signals (SIGINT, SIGTERM)
  • Handle uncaughtException and unhandledRejection
  • Execute shutdown tasks in a controlled manner
  • Enforce timeout-based forced shutdown fallback

Refactored Server Bootstrap

  • Removed inline graceful shutdown logic from startServer()
  • Integrated ShutdownManager for lifecycle handling
image

Author

Suthar Dhiraj
Full Stack Developer

  • Focus on Event-driven system, observability, microservices, devOps

@rahulnikam2002
Copy link
Copy Markdown
Owner

Great work @dhirajsuthar781 - Glad you are solving real problems!
I'll review and merge this.

@rahulnikam2002 rahulnikam2002 added the enhancement New feature or request label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants