fix(NODE-7411): iterate all servers in closeCheckedOutConnections()#4847
fix(NODE-7411): iterate all servers in closeCheckedOutConnections()#4847Nepomuk5665 wants to merge 2 commits intomongodb:mainfrom
Conversation
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.
|
Hi @Nepomuk5665 thanks so much for the work on this PR. We're currently reviewing this and will get back to you soon. |
|
@Nepomuk5665 fantastic job, thanks for pointing out this problem. Could you please modify the existing test inside There are currently two issues with the test:
|
…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
|
Thanks for the feedback @tadjik1! I've updated the test with the following changes:
This ensures that in multi-server deployments, the test will exercise connections to both primary and secondary servers, validating that the fix properly checks in connections across all servers on close. |
|
@Nepomuk5665, thanks for the update! Can you please take a look into it? In addition to that I have a feeling that we might have not enough coverage for this specific functionality and it might be a good idea to add additional tests inside |
Summary
Fix a bug in
Topology.closeCheckedOutConnections()where only the first server's checked-out connections were being closed.The Bug
The method had a premature
returnstatement inside theforloop:This caused the method to:
closeCheckedOutConnections()on itThe Fix
Remove the
returnstatement so all servers are iterated:Impact
This bug affects multi-server topologies (replica sets, sharded clusters) where only the first server's connections would be properly closed when
MongoClient.close()is called. This could lead to: