feat(api): MongoDB reconnect, bounded timeouts and graceful shutdown#652
feat(api): MongoDB reconnect, bounded timeouts and graceful shutdown#652Kuchizu wants to merge 5 commits into
Conversation
neSpecc
left a comment
There was a problem hiding this comment.
I’m only seeing retries on the initial connection. Where is the reconnection on the failing MongoDB connection?
There was a problem hiding this comment.
Pull request overview
This PR improves MongoDB connection resilience and shutdown behavior in the API: it adds bounded MongoDB timeouts (so queries fail fast during outages), startup retry logic, and graceful shutdown handlers to close connections cleanly.
Changes:
- Add MongoClient options to bound server selection / socket timeouts and enable retry reads/writes.
- Implement MongoDB startup connect-with-retry plus heartbeat transition logging, and add
closeConnections()for graceful shutdown. - Register SIGINT/SIGTERM shutdown handlers to close HTTP, MongoDB, and Redis connections; bump package version to 1.5.1.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/mongo.ts | Adds bounded Mongo options, startup retry connect, heartbeat monitoring, and connection close helper. |
| src/index.ts | Adds SIGINT/SIGTERM shutdown handling to close HTTP/Mongo/Redis. |
| package.json | Bumps package version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| } | ||
|
|
||
| throw new Error(`[Mongo:${name}] unreachable`); |
There was a problem hiding this comment.
seems that two errors
throw new Error(`[Mongo:${name}] failed after ${reconnectTries} attempts: ${message}`);
and
throw new Error(`[Mongo:${name}] unreachable`);
would always come together, could we leave only one?
Runtime reconnection is already handled by the driver itself |
Retry on startup. Queries fail fast during outages instead of hanging. Driver handles recovery on its own.