Skip to content

[BUG] : Missing Graceful Shutdown in Express Server #128

Description

@JyantiM

Describe the bug
The backend does not cleanly close database connections or finish pending requests when the server receives a kill signal like SIGTERM or SIGINT. Right now, if the process gets killed (deployment restart, container shutdown, manual stop, etc.), it just dies immediately, cutting off any requests that were still in progress and leaving the MongoDB connection open instead of closing it properly.

To Reproduce

  1. Start the server locally (npm run dev or equivalent in apps/api).
  2. Send a request that takes a moment to complete, or just leave the server running.
  3. Kill the process with a SIGTERM (e.g. kill <pid>) or Ctrl+C for SIGINT.
  4. Observe that the process exits immediately with no cleanup, no closing of the MongoDB connection, and no chance for any in-flight request to finish.

Expected behavior
On receiving SIGTERM or SIGINT, the server should:

  • Stop accepting new connections.
  • Let any in-flight requests finish.
  • Close the MongoDB connection cleanly via mongoose.connection.close().
  • Then exit the process.

This requires capturing the server instance from app.listen() in apps/api/index.js and adding process.on('SIGTERM', ...) and process.on('SIGINT', ...) listeners to handle the shutdown sequence.

Additional context
I'd like to work on this issue myself if it's approved.

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