fix(db): retry initial Mongo connection to avoid worker crash-loop#559
Open
Kuchizu wants to merge 1 commit into
Open
fix(db): retry initial Mongo connection to avoid worker crash-loop#559Kuchizu wants to merge 1 commit into
Kuchizu wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the MongoDB DatabaseController.connect() startup behavior so workers don’t crash-loop when MongoDB is temporarily unreachable, by retrying the initial connection handshake with a fixed delay and a bounded server-selection timeout.
Changes:
- Add configurable retry loop for the initial MongoDB connection attempt (
MONGO_RECONNECT_TRIES,MONGO_RECONNECT_INTERVAL). - Add
serverSelectionTimeoutMSto ensure each attempt fails fast during outages. - Adjust
connect()to return the existingDbinstance when already connected.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+80
to
+81
| const tries = Number(process.env.MONGO_RECONNECT_TRIES) || DEFAULT_RECONNECT_TRIES; | ||
| const intervalMs = Number(process.env.MONGO_RECONNECT_INTERVAL) || DEFAULT_RECONNECT_INTERVAL_MS; |
| serverSelectionTimeoutMS: SERVER_SELECTION_TIMEOUT_MS, | ||
| ...(this.appName ? { appName: this.appName } : {}), | ||
| }); | ||
| this.db = await this.connection.db(); |
Comment on lines
+83
to
+84
| for (let attempt = 1; attempt <= tries; attempt++) { | ||
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DatabaseController.connect() now retries the initial handshake instead of throwing on the first failure.