Skip to content

fix: implement graceful shutdown for Express server - #952

Open
ParthBhuptani wants to merge 1 commit into
parthbuilds-community:mainfrom
ParthBhuptani:fix/graceful-shutdown
Open

fix: implement graceful shutdown for Express server#952
ParthBhuptani wants to merge 1 commit into
parthbuilds-community:mainfrom
ParthBhuptani:fix/graceful-shutdown

Conversation

@ParthBhuptani

Copy link
Copy Markdown
Member

📋 What does this PR do?

Updates server/index.js to handle SIGTERM and SIGINT signals
gracefully instead of killing the process instantly.

When a shutdown signal is received:

  1. Stops accepting new incoming requests (server.close())
  2. Waits for existing in-flight HTTP requests to finish
  3. Cleanly closes the MongoDB connection (mongoose.connection.close())
  4. Exits the process cleanly (process.exit(0))

🔗 Related Issue

Closes #940

🛠️ Changes Made

  • server/index.js — stored server instance in a variable and added
    graceful shutdown handler for SIGTERM and SIGINT signals

✅ Benefits

  • Prevents data corruption during deployments
  • Prevents users getting abrupt 502 errors during server restarts
  • Required for zero-downtime deployments and Docker scaling

✅ Checklist

  • I've read the CONTRIBUTING guide
  • My code follows the project's style guidelines
  • I've linked the related issue
  • I haven't introduced any new secrets or API keys

@github-actions github-actions Bot added refactor Improve code without changing functionality backend labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend refactor Improve code without changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reliability: Implement Graceful Shutdown for the Express server

1 participant