fix(NODE-7298): ensure commonWireVersion is computed from server maxWireVersion#4805
fix(NODE-7298): ensure commonWireVersion is computed from server maxWireVersion#4805tadjik1 merged 11 commits intomongodb:mainfrom
Conversation
|
Fantastic job @crehbichler, thanks a lot! Can you please also add integration test for the specific scenario you've found in the jira ticket, i.e. |
…ge using provided read preference
|
Added! I wasn’t 100% sure whether to place the integration test in Also, in the test I am checking the server address (I used the hello command) because the correct $readPreference was already attached to the command before the fix (just the wrong server was being selected). Please let me know if this is fine or if I should adjust anything. |
I think this is valid approach, another can be to issue 2 aggregate commands with and w/o |
…update() accordingly
|
@crehbichler thanks a lot for updating the PR! Some tests are failing, we will investigate failures and come back with an update in upcoming days. Sorry for the delay 🙏 |
tadjik1
left a comment
There was a problem hiding this comment.
Thanks a lot @crehbichler, great work!
Description
Summary of Changes
The TopologyDescription constructor initialized commonWireVersion to 0, but the update() method only updates this field when its previous value is null. As a result, commonWireVersion remained stuck at 0 even when all servers reported valid non-zero maxWireVersion values.
This caused secondaryWritableServerSelector() to treat the cluster as pre–MongoDB 5.0 (because wireVersion < 13) and always fall back to primary read preference. User-provided read preferences (e.g. secondary, secondaryPreferred) were therefore ignored for aggregation pipelines containing write stages ($merge and $out).
The fix initializes commonWireVersion to null, allowing it to be correctly updated to the minimum non-zero maxWireVersion across server descriptions.
A new test file
test/unit/sdam/topology_description.test.tshas been added to cover initialization and update behavior.Release Highlight
Fixed Read Preference adherence for
$mergeand$outaggregations.Resolved an issue where the driver failed to detect MongoDB 5.0+ capabilities due to incorrect
commonWireVersioninitialization. This ensures that aggregations with write stages now correctly respectsecondaryandsecondaryPreferredread preferences, rather than forcing execution on the Primary.Huge thanks to @crehbichler for discovering, investigating this bug and for implementing a fix!
Double check the following
npm run check:lint)type(NODE-xxxx)[!]: description