-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 1.4.1
-
Component/s: libmongoc
-
None
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.