Skip to content

fix(NODE-7411): closeCheckedOutConnections iterates all servers and fixes test regression#4917

Open
sarthaksoni25 wants to merge 3 commits intomongodb:mainfrom
sarthaksoni25:nepomuk-fix
Open

fix(NODE-7411): closeCheckedOutConnections iterates all servers and fixes test regression#4917
sarthaksoni25 wants to merge 3 commits intomongodb:mainfrom
sarthaksoni25:nepomuk-fix

Conversation

@sarthaksoni25
Copy link
Copy Markdown

@sarthaksoni25 sarthaksoni25 commented Apr 11, 2026

Description

Summary of Changes

Fixes a bug in closeCheckedOutConnections() in topology.ts where a premature return caused cleanup to stop after the first server, skipping checked-out connections on remaining servers in multi-server topologies such as replica sets and sharded clusters.

Notes for Reviewers

  • The premature return has been replaced so the loop iterates all servers
  • The existing ConnectionCheckedInEvent test in connection_pool.test.ts has been fixed — it previously used readPreference: 'secondaryPreferred' which could route to secondaries where no failpoint was configured, making the test ineffective
  • A dedicated closeCheckedOutConnections test has been added in client_close.test.ts to verify the CMAP requirement that each connectionCheckedIn event is immediately followed by connectionClosed for in-flight connections during client.close()

This PR includes Nepomuk's original fix commit. Relates to #4847.

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed
  • PR title follows the correct format: fix(NODE-7411): closeCheckedOutConnections iterates all servers and fixes test regression
  • Changes are covered by tests
  • No new TODOs

@sarthaksoni25 sarthaksoni25 requested a review from a team as a code owner April 11, 2026 12:44
Nepomuk5665 and others added 3 commits April 11, 2026 18:21
The method had a premature 'return' inside the for loop, which caused it
to only close connections on the first server and exit immediately. This
fix removes the return statement so all servers have their checked-out
connections closed when MongoClient.close() is called.

This bug would affect multi-server topologies (replica sets, sharded
clusters) where only the first server's connections would be properly
closed.
…deployments

- Remove 'single' topology restriction from metadata to support replicaset/sharded
- Use readPreference: 'secondaryPreferred' to exercise connections to secondaries
- Switch from insert to find operations to validate reads against secondaries
@dariakp dariakp added tracked-in-jira Ticket filed in MongoDB's Jira system External Submission PR submitted from outside the team labels Apr 15, 2026
@tadjik1
Copy link
Copy Markdown
Member

tadjik1 commented Apr 21, 2026

hi @sarthaksoni25, thank you so much for your work on this task! This ticket is currently in our queue and team will review your changes once we have capacity. You can follow linked Jira ticket or this PR for updates.
Meanwhile, can you please update PR description to follow our PR description template? This will simplify review process for us.

@sarthaksoni25
Copy link
Copy Markdown
Author

Thanks for the feedback, Sergey! I've updated the PR description to follow the template. Let me know if there's anything else you'd like me to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Submission PR submitted from outside the team tracked-in-jira Ticket filed in MongoDB's Jira system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants