|
`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.
https://github.com/mongodb/mongo/blob/0cceba6f04b95f3652de84c2f1f4ab2a644dba6e/src/mongo/db/repl/topology_coordinator.cpp#L291
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.
|