Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-820

cluster next_primary method returns nil with empty standalone config

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.0
    • Affects Version/s: 2.0.0
    • Component/s: None
    • None

      When the standalone config is empty, e.g., after an error or after stopping the server, on the next insert operation, Cluster#next_primary returns nil and causes errors up the call chain. The cluster.service.scan! call path demonstrates that each server config is updated by the results of the ismaster command, or empty {} for any error.

      The following is a possible fix.

        class Cluster
          def next_primary
            if client.cluster.mode == Mongo::Cluster::Mode::ReplicaSet
              primary = client.server_preference.primary(servers).first
            else
              primary = servers.first
            end
            raise Mongo::NoMaster.new("no master") unless primary
            primary
          end
        end
      

      There's probably a better way to fix this via the server_preference mechanism, but at least the above should help to clarify the problem.

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            gjmurakami Gary Murakami
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: