[CDRIVER-3633] read pref with max_staleness_seconds may not be sent Created: 23/Apr/20  Updated: 28/Oct/23  Resolved: 04/May/20

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.4.1
Fix Version/s: 1.17.0-beta2, 1.17.0

Type: Bug Priority: Major - P3
Reporter: Roberto Sanchez Assignee: Roberto Sanchez
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

While inspecting mongoc-read-prefs.c during implementation of hedged reads, it was discovered that the C driver does not properly handle sending read preference to mongos for secondary preferred mode with a specified max_staleness_seconds.

Prior to the hedged reads change, the server selection spec stated:

  - For mode 'secondaryPreferred', drivers MUST set the ``slaveOK`` wire protocol flag.
    If the read preference contains a non-empty ``tag_sets`` parameter,
    or ``maxStalenessSeconds`` is a positive integer, drivers MUST
    use ``$readPreference``; otherwise, drivers MUST NOT use ``$readPreference``

However, the logic in the _apply_read_preferences_mongos function was never updated for the implementation of the max_staleness_seconds option.

The logic is currently:

   if (mode == MONGOC_READ_SECONDARY_PREFERRED && bson_empty0 (tags)) {
       result->flags |= MONGOC_QUERY_SLAVE_OK;
 
    } else if (mode != MONGOC_READ_PRIMARY) {

Therefore, a read preference of mode MONGOC_READ_SECONDARY_PREFERRED with a positive integer value for max_staleness_seconds will NOT be communicated to mongos as required by the spec. However, if the read preference happens to have specified the tags parameter, then correct behavior will be observed.



 Comments   
Comment by Githook User [ 25/May/20 ]

Author:

{'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}

Message: CDRIVER-3633 make max_staleness_seconds send read pref
Branch: r1.17
https://github.com/mongodb/mongo-c-driver/commit/b9493f785ce023e174d75df67553716ee270a052

Comment by Githook User [ 04/May/20 ]

Author:

{'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}

Message: CDRIVER-3633 make max_staleness_seconds send read pref
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/e319a583bc19388ae02672828a5ed5a3c9076fa8

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