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

Summary

  • 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.

  • Fixes the ConnectionCheckedInEvent test in connection_pool.test.ts. The previous test used readPreference: 'secondaryPreferred', which could route find operations to secondaries where no failpoint was configured. As a result, the finds could complete before client.close() was called, making the test ineffective for validating in-flight connection cleanup.

  • Adds a dedicated closeCheckedOutConnections test in client_close.test.ts to verify the CMAP requirement that, for in-flight connections during client.close(), each connectionCheckedIn event is immediately followed by connectionClosed.

Test verification

Verified on a local 3-node replica set:

  • With the return bug restored → the ConnectionCheckedInEvent test fails
  • With the fix applied → the test passes

Note: this branch includes Nepomuk’s original fix commit. (Relates to #4847)
This is my first contribution to this repository.

@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
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