-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
Replication 2021-12-13, Replication 2021-12-27
`readPreference == ReadPreference::PrimaryOnly` on line 291 will never evaluate to false because there is exactly the same parent `if` check. Which means the `else` block is unreachable.
First, the code was introduced with this PR https://github.com/mongodb/mongo/commit/7296a460f826c8a618147e09606c5f1935c482a4 The outer check has two ORed conditions:
if (readPreference == ReadPreference::PrimaryOnly ||
(chainingPreference == ChainingPreference::kUseConfiguration &&
!_rsConfig.isChainingAllowed()))
Which means the inner check can evaluate false.
Later, with this change https://github.com/mongodb/mongo/commit/a7ff5838b5a4bcb4881a08c5dafce671c3b54940 the condition in the outer `if` statement is changed and the inner `if` can never be false anymore.
The issue was found by an external user trungtechnews@gmail.com.