[CDRIVER-1353] SecondaryPreferred fails if primary matches tags but secondaries don't. Created: 03/Jul/16  Updated: 10/Aug/16  Resolved: 05/Jul/16

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.2.0
Fix Version/s: 1.4.0

Type: Bug Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends

 Description   

Server Selection logic bug. Assume a primary P and secondary S, and a read preference with mode SecondaryPreferred and a tag set. S doesn't match the tag set, so the driver should fall back to using the primary.

There's a bug if P happens to match the read preference's tag set. The driver selects no servers instead of using the primary.

mongoc_topology_description_suitable_servers's logic is:

1. Set has_secondary true, because there is a secondary S.
2. Select "eligible" servers according to the tag set: this leaves only P.
3. Since there is at least one eligible server, leave has_secondary true.
4. Since has_secondary is true and mode is SecondaryPreferred, remove P from suitable servers.
5. Now there are no suitable servers, selection fails.

The bug is near #3: has_secondary should only be true if there is an eligible secondary, rather than if there is any eligible server?

Another option is to partly rewrite the C Driver's server selection based on how other clients do SecondaryPreferred: try selection with mode Secondary, if that fails then select with mode Primary. For PrimaryPreferred, vice versa.



 Comments   
Comment by Githook User [ 05/Jul/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1353 SecondaryPreferred can fail if primary matches
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/89e1f9898200e52888f0b5b3b5a4a0ecceb73f6f

Generated at Wed Feb 07 21:12:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.