Skip to content

fix: bad auth error #178

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

Merged
merged 6 commits into from
Apr 30, 2025
Merged

fix: bad auth error #178

merged 6 commits into from
Apr 30, 2025

Conversation

fmenezes
Copy link
Collaborator

@fmenezes fmenezes commented Apr 30, 2025

This essentially keeps trying to connect because after user is created it might take some time for it to be available.

note: also making deletion of user async on disconnect to reduce change of timeout

@fmenezes fmenezes changed the title fmenezes/fix bad auth fix: bad auth Apr 30, 2025
@fmenezes fmenezes marked this pull request as ready for review April 30, 2025 10:47
@Copilot Copilot AI review requested due to automatic review settings April 30, 2025 10:47
@fmenezes fmenezes requested review from blva and a team as code owners April 30, 2025 10:47
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request addresses authentication issues by implementing a retry mechanism for connecting to the MongoDB cluster and making user deletion asynchronous.

  • Introduces a retry loop for connecting to MongoDB in connectCluster.ts.
  • Adjusts user deletion in session.ts to run asynchronously to prevent timeouts.
  • Adds a new logging identifier in logger.ts to support the retry mechanism.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/tools/atlas/metadata/connectCluster.ts Adds a retry loop for connecting to MongoDB with logging on failure
src/session.ts Refactors user deletion to be asynchronous using promise chaining
src/logger.ts Adds a new logging identifier for connection failures

Comment on lines 103 to 106

await this.session.connectToMongoDB(connectionString, this.config.connectOptions);
for (let i = 0; i < 20; i++) {
try {
await this.session.connectToMongoDB(connectionString, this.config.connectOptions);
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

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

If all retry attempts fail, the connection error is silently swallowed. Consider throwing an error or returning a failure state after exhausting all attempts.

Suggested change
await this.session.connectToMongoDB(connectionString, this.config.connectOptions);
for (let i = 0; i < 20; i++) {
try {
await this.session.connectToMongoDB(connectionString, this.config.connectOptions);
let connected = false;
for (let i = 0; i < 20; i++) {
try {
await this.session.connectToMongoDB(connectionString, this.config.connectOptions);
connected = true;

Copilot uses AI. Check for mistakes.

@fmenezes fmenezes changed the title fix: bad auth fix: bad auth error Apr 30, 2025
let lastError: Error | undefined = undefined;

for (let i = 0; i < 20; i++) {
try {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can we add tests for this in a follow-up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in the integration tests we can't force a user to take longer to be created, we could try with unit tests, but none of the tools are covered in unit at the moment

@fmenezes fmenezes merged commit 09d92e7 into main Apr 30, 2025
16 checks passed
@fmenezes fmenezes deleted the fmenezes/fix_bad_auth branch April 30, 2025 13:10
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.

2 participants