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

Ruby Driver Incorrectly Reports Value for next_primary

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Works as Designed
    • Affects Version/s: 2.4.0
    • Fix Version/s: None
    • Component/s: Public API
    • Labels:
    • Environment:
      Mongo DB Version 3.2.7 on Ubuntu 14.04

      Description

      We're using the Ruby MongoDB driver to detect if a server is the primary node of a replica set using the following check that's ran on each node of the replica set:

      client = Mongo::Client.new(
          [server], :connect => :direct, :connect_timeout => 3, :ssl => true, :ssl_cert => '/etc/mongocerts/mongodb.pem', :ssl_key => '/etc/mongocerts/mongodb.pem',  :ssl_ca_cert => '/etc/mongocerts/cacert.pem', :ssl_verify => true, :database => 'test'
      )
       
      this_server = get_address_of_this_server() # A little function which returns the address of this server, have verified it returns the correct address
       
      return true if client.cluster.next_primary.address.to_s == this_server
      

      The problem is that no matter what node we run this on `client.cluster.next_primary.address.to_s` returns the address of the node it's being ran on, and not that of the primary node.

      I've been staring at this for a long time and can't see what we're doing wrong. Am I misunderstanding the API or is this a bug?

        Attachments

          Activity

            People

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            AKalair Aaron [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: