Skip to content

fix(NODE-7411): iterate all servers on close#4967

Draft
johnmtll wants to merge 7 commits into
mainfrom
NODE-7411/iterate-all-servers-on-close
Draft

fix(NODE-7411): iterate all servers on close#4967
johnmtll wants to merge 7 commits into
mainfrom
NODE-7411/iterate-all-servers-on-close

Conversation

@johnmtll

@johnmtll johnmtll commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Description

Summary of Changes

Supplants:

  1. fix(NODE-7411): closeCheckedOutConnections iterates all servers and fixes test regression #4917
  2. fix(NODE-7411): iterate all servers in closeCheckedOutConnections() #4847

Additional Coverage:

  1. Adds additional coverage for resource clearing to the mongo client tests, ensuring that cursors and sessions are properly wiped after closure, regardless of connection state. Also closes a missing test gap which ensures duplicate/misordered calls of connect()/close() dont cause fatal behaviour (increasing coverage slightly).

  2. Adjusts client closure SDAM tests to ensure event ordering is maintained when a closure spans 2 connection pools.

Notes for Reviewers
  1. This is a technical glue test fixture duplication (SDAM validation) across connection_pool.test.ts and client_close.test.ts.
    Connpool tests validate SDAM requirements at the connpool level, whereas the clientclose tests ensure that those requirements persist when a coordinator attempts to close all connections across mutliple connpools. The domain of this 'coordination testing' is explicitly owned by the client close tests and the extension of the duplicate behaviour in connection_pool.test.ts is where domain-affinity to the mongo client is solidified.

What is the motivation for this change?

Release Highlight

Release notes highlight

Double check the following

  • Lint is passing (npm run check:lint)
  • 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

Nepomuk5665 and others added 4 commits June 16, 2026 15:24
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
@johnmtll johnmtll force-pushed the NODE-7411/iterate-all-servers-on-close branch from 39e064b to 1b7b0c5 Compare June 19, 2026 18:14
@johnmtll johnmtll force-pushed the NODE-7411/iterate-all-servers-on-close branch from 7c08cc1 to 7c109ec Compare June 19, 2026 18:20
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.

3 participants