Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-61608

Unreachable code in topology_coordinator.cpp

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.3.0
    • 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.

      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.

            Assignee:
            frederic.vitzikam@mongodb.com Frederic Vitzikam (Inactive)
            Reporter:
            alexey.anisimov@mongodb.com Alexey Anisimov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: