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

fix(NODE-5225): concurrent MongoClient.close() calls each attempt to close the client #4376

Merged
merged 10 commits into from
Jan 29, 2025

Conversation

aditi-khare-mongoDB
Copy link
Contributor

@aditi-khare-mongoDB aditi-khare-mongoDB commented Jan 22, 2025

Description

Previously, concurrent calls to client.close() would throw an error.

What is changing?

This PR introduces a locking mechanism on client.close(). The

Is there new documentation needed for these changes?

No.

What is the motivation for this change?

User submitted bug: NODE-5225

Release Highlight

MongoClient.close() can be called concurrently

In the past, concurrent calls to MongoClient.close() had poorly defined behavior depending on the exact timing of the second (or more) calls to close(). In some cases, this could also throw errors.

With these changes, MongoClient.close() can be called concurrently safely and always return the same promise.

Note

This is intended as a correctness fix - we don't recommend calling MongoClient.close() concurrently if it can be avoided.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@aditi-khare-mongoDB aditi-khare-mongoDB marked this pull request as ready for review January 23, 2025 18:36
@baileympearson baileympearson self-assigned this Jan 23, 2025
@baileympearson baileympearson added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jan 23, 2025
@baileympearson baileympearson self-requested a review January 23, 2025 19:06
src/mongo_client.ts Outdated Show resolved Hide resolved
test/integration/node-specific/mongo_client.test.ts Outdated Show resolved Hide resolved
@aditi-khare-mongoDB aditi-khare-mongoDB changed the title fix(NODE-5225): Concurrent calls to client.close() throw fix(NODE-5225): Concurrent MongoClient.close() calls each attempt to close the client Jan 24, 2025
Copy link
Contributor

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

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

Just one last change

src/mongo_client.ts Outdated Show resolved Hide resolved
@baileympearson baileympearson added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Jan 28, 2025
@aditi-khare-mongoDB aditi-khare-mongoDB changed the title fix(NODE-5225): Concurrent MongoClient.close() calls each attempt to close the client fix(NODE-5225): concurrent MongoClient.close() calls each attempt to close the client Jan 28, 2025
@baileympearson baileympearson merged commit 9419af7 into main Jan 29, 2025
22 of 27 checks passed
@baileympearson baileympearson deleted the NODE-5225/close-lock branch January 29, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants