Conversation
There was a problem hiding this comment.
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
cachedPromiseto memoize theMongoClient.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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| .catch((error) => { | ||
| client.close().catch(() => {}); |
There was a problem hiding this comment.
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.
| .catch((error) => { | |
| client.close().catch(() => {}); | |
| .catch(async (error) => { | |
| try { | |
| await client.close(); | |
| } catch { | |
| // Ignore errors while closing the client | |
| } |
No description provided.