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
- Start the server locally (npm run dev or equivalent in apps/api).
- Send a request that takes a moment to complete, or just leave the server running.
- Kill the process with a SIGTERM (e.g.
kill <pid>) or Ctrl+C for SIGINT.
- 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.
Describe the bug
The backend does not cleanly close database connections or finish pending requests when the server receives a kill signal like
SIGTERMorSIGINT. 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
kill <pid>) or Ctrl+C for SIGINT.Expected behavior
On receiving SIGTERM or SIGINT, the server should:
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.