Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: retry initial MongoDB connections #5807

Merged
merged 1 commit into from
Nov 14, 2019

Conversation

aldeed
Copy link
Contributor

@aldeed aldeed commented Nov 14, 2019

Resolves #5806
Impact: minor
Type: feature

Issue

When spinning up separate API and MongoDB containers, due to timing the API container may try to connect to MongoDB before it is fully ready. Now that API starts up faster in 3.0.0, this is more likely. The MongoDB driver library does not auto-retry connecting on the first connection.

Solution

Adds our own auto-retry logic for the first connection, as well as better logging about what is happening with db connections.

Breaking changes

None

Testing

  1. Start api service but not mongo service. Verify that you see logging about retrying 10 times and it eventually gives up and exits the app with the error. (In a development environment, you'll see this whole series of connection logs twice because it first tries to auto-init the replica set.)
  2. Start api service but not mongo service. While it's showing the retrying log messages in API logs, start the mongo service. You'll have about 30 seconds window to do so. Verify in the API logs that it eventually shows a successful db connection before it fully times out.
  3. Start both api and mongo services normally. Verify that it shows a successful db connection in the logs on the first or second try.

@aldeed aldeed self-assigned this Nov 14, 2019
@aldeed aldeed requested a review from willopez November 14, 2019 18:15
Copy link
Contributor

@focusaurus focusaurus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Copy link
Member

@willopez willopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, works as advertized

@aldeed aldeed merged commit f3a1da9 into release-3.0.0 Nov 14, 2019
@aldeed aldeed deleted the feat-aldeed-5806-mongo-reconnect branch November 14, 2019 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants