Skip to content

update cached client#408

Merged
michelleyeoh merged 8 commits intomainfrom
mongoclient-fix
Feb 28, 2026
Merged

update cached client#408
michelleyeoh merged 8 commits intomainfrom
mongoclient-fix

Conversation

@michelleyeoh
Copy link
Contributor

No description provided.

Copy link

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

Updates the MongoDB client utility to cache the in-flight connection promise so concurrent callers share a single connection attempt, reducing duplicate connections in the API layer.

Changes:

  • Added cachedPromise to memoize the MongoClient.connect() call.
  • Updated getClient() to await the cached promise and store the connected client.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +24 to +25
.catch((error) => {
client.close().catch(() => {});
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

client.close() is kicked off but not awaited in the connect error handler. That means a retry can start while the previous client is still closing, which can leak sockets / create extra connections under failure conditions. Consider making this .catch handler async and awaiting client.close() (or await client?.close() if you refactor) before clearing the cached state and rethrowing.

Suggested change
.catch((error) => {
client.close().catch(() => {});
.catch(async (error) => {
try {
await client.close();
} catch {
// Ignore errors while closing the client
}

Copilot uses AI. Check for mistakes.
@michelleyeoh michelleyeoh merged commit 95ceb87 into main Feb 28, 2026
2 checks passed
@michelleyeoh michelleyeoh deleted the mongoclient-fix branch February 28, 2026 05:53
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