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

Ruby Driver Incorrectly Reports Value for next_primary

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Minor - P4
    • Resolution: Works as Designed
    • 2.4.0
    • None
    • Public API
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: