Skip to content

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

Merged
PavelSafronov merged 25 commits into
mainfrom
NODE-7411/iterate-all-servers-on-close
Jul 6, 2026
Merged

PavelSafronov merged 25 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 client closure spans 2 connection pools.

Notes for Reviewers

This is technically duplicating coverage across another integration test fixture: connection_pool.test.ts and client_close.test.ts:

Connpool tests validate SDAM requirements at the connpool level, whereas the client-close 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.

What is the motivation for this change?

Release Highlight

MongoClient.close() now closes in-use connections on all servers

Since v6.17.0, MongoClient.close() has eagerly closed checked-out (in-use) connections so that in-flight operations are interrupted promptly with a MongoClientClosedError instead of holding the client open. However, due to a bug, on replica sets and sharded clusters operations in flight on other servers were not interrupted, and their connections stayed open until the operations completed on their own. Calls to closeCheckedOutConnections() will now ensure all checked out connections are closed across all servers.

Thank you to @Nepomuk5665 and @sarthaksoni25 for bringing this to our attention/providing an initial implementation!

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a shutdown bug in SDAM topology cleanup where MongoClient.close() only closed checked-out connections for the first server in a multi-server topology, and extends integration test coverage to validate resource clearing and CMAP event ordering during client close.

Changes:

  • Fix Topology.closeCheckedOutConnections() to iterate and close checked-out connections for all servers in the topology.
  • Add/adjust integration tests to verify client resource clearing (cursors/sessions) across connect/close orderings and to validate CMAP event sequencing when closing across multiple pools.
  • Add an Evergreen orchestration wrapper script to echo configuration and set PATH for binaries.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/sdam/topology.ts Removes premature return so all servers’ checked-out connections are closed on client shutdown
test/integration/node-specific/client_close.test.ts Adds resource-clearing tests and a multi-pool closeCheckedOutConnections CMAP ordering test
test/integration/connection-monitoring-and-pooling/connection_pool.test.ts Adjusts CMAP test to use find failpoint/operations and broadens metadata requirements
.evergreen/run-orchestration.sh Adds wrapper script for drivers-tools orchestration with environment echoing/PATH setup

@johnmtll
johnmtll force-pushed the NODE-7411/iterate-all-servers-on-close branch from a4e24bf to 1ccfe1d Compare June 23, 2026 14:10
@johnmtll
johnmtll marked this pull request as ready for review June 25, 2026 00:16
@johnmtll
johnmtll requested a review from a team as a code owner June 25, 2026 00:16

@PavelSafronov PavelSafronov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code changes look good, good test coverage, and CI failures appear to be unrelated. Approving.

@PavelSafronov PavelSafronov self-assigned this Jun 26, 2026
@PavelSafronov PavelSafronov added the Team Review Needs review from team label Jun 26, 2026
@PavelSafronov
PavelSafronov requested a review from a team June 26, 2026 20:18

@nbbeeken nbbeeken left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Prob want some release notes promoting the value of upgrading to this version to get the leak fix

@PavelSafronov
PavelSafronov merged commit 72c0296 into main Jul 6, 2026
19 of 33 checks passed
@PavelSafronov
PavelSafronov deleted the NODE-7411/iterate-all-servers-on-close branch July 6, 2026 22:06
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.

6 participants