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

Reconnection problem with ReplicaSets (manager has invalid seeds)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 12_01_17
    • Affects Version/s: 1.7.0
    • Component/s: Replica Set
    • Environment:
      MongoDB 2.0.6
      gem mongo version 1.7.0 vs. 1.6.x

      Let's consider a minimal usage of replicaSets with 3 nodes (primary on port 27017, secondary on 27018 and arbiter on 27019), and let's follow the following steps:

      1. connect to mongo
      2. do a read operation (ok)
      3. kill the primary node (on port 27017)
      4. do a read operation repeatedly (fails until reconnection to primary, now on port 27018)
      5. re-launch the node on port 27017 (which is now a secondary node)
      6. kill the primary node (on port 27018)
      7. do a read operation repeatedly (fails until reconnection to primary, now on port 27017)

      This sequence is working fine with the driver version 1.6.2, but does not work anymore with the driver version 1.7.0.

      After step 4., the connection manager will only have one seed (port 27018), so after step 6. the manager will not be able to reconnect anymore because the node on port 27018 is down now...

      It used to work with the driver version 1.6.x because the driver always tried to reconnect with the original seeds, see:
      https://github.com/mongodb/mongo-ruby-driver/blob/1.6.2/lib/mongo/util/pool_manager.rb#L297

      Is this new behavior wanted by design or is it a regression?

      See below 2 examples with each version of the driver:

      With ruby driver version 1.6.2, works fine:

      require 'rubygems'
      gem 'mongo', '1.6.2'
      require 'mongo'
      
      hosts = ["localhost:27017", "localhost:27018", "localhost:27019"]
      #         primary         ,  secondary       , arbiter
      
      @conn= Mongo::ReplSetConnection.new( hosts )
      @db  = @conn['sample-db']
      
      @db.collection_names
      # => []
      
      # kill the primary mongod process on port 27017
      # the process on port 27018 is elected primary
      
      @db.collection_names
      # => Mongo::ConnectionFailure: Operation failed with the following exception: Mongo::ConnectionFailure
      
      @db.collection_names
      # => []
      
      # re-launch the mongod process on port 27017
      #  then
      # kill the primary mongod process on port 27018
      # the process on port 27017 is elected primary
      
      @db.collection_names
      # => Mongo::ConnectionFailure: Operation failed with the following exception: connection closed
      
      @db.collection_names
      # => []
      
      @conn.seeds
      # => [["localhost", 27017], ["localhost", 27018], ["localhost", 27019]] 
      

      With ruby driver version 1.7.0, cannot reconnect:

      require 'rubygems'
      gem 'mongo', '1.7.0'
      require 'mongo'
      
      hosts = ["localhost:27017", "localhost:27018", "localhost:27019"]
      #         primary         ,  secondary       , arbiter
      
      @conn= Mongo::ReplSetConnection.new( hosts )
      @db  = @conn['sample-db']
      
      @db.collection_names
      # => []
      
      @conn.manager.seeds
      # => [["localhost", 27017], ["localhost", 27018]]
      
      # kill the primary mongod process on port 27017
      # the process on port 27018 is elected primary
      
      @db.collection_names
      # => Mongo::ConnectionFailure: Operation failed with the following exception: ...
      
      @db.collection_names
      # => Mongo::ConnectionFailure: Could not checkout a socket.
      
      @db.collection_names
      # => []
      
      @conn.manager.seeds
      # => [["localhost", 27018]]
      
      # re-launch the mongod process on port 27017
      #  then
      # kill the primary mongod process on port 27018
      # the process on port 27017 is elected primary
      
      @db.collection_names
      # => Mongo::ConnectionFailure: Operation failed with the following exception: ...
      
      @db.collection_names
      # => Mongo::ConnectionFailure: Could not checkout a socket.
      
      @db.collection_names
      # => Mongo::ConnectionFailure: Cannot connect to a replica set using seeds localhost:27018
      
      @conn.manager.seeds
      # => [["localhost", 27018]]
      #
      # but process on port 27018 is down!!!
      #
      # whereas:
      @conn.seeds
      # => [["localhost", 27017], ["localhost", 27018], ["localhost", 27019]]
      

            Assignee:
            tyler@10gen.com Tyler Brock
            Reporter:
            maxime Maxime RETY
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: