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

Replica set :read option of :nearest fails with "undefined local variable or method `pools' for #<Mongo::MongoReplicaSetClient:0x6b18617f>"

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 1.8.6
    • Affects Version/s: 1.8.5
    • Component/s: Replica Set

      If you attempt to create a Mongo::MongoReplicaSetClient with the :read option of :nearest, it fails with this error every time.

      ERROR: <NameError> undefined local variable or method `pools' for #<Mongo::MongoReplicaSetClient:0x6b18617f>
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/util/read_preference.rb:80:in `select_pool'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/util/read_preference.rb:53:in `read_pool'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/mongo_replica_set_client.rb:342:in `checkout_reader'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/mongo_replica_set_client.rb:326:in `checkout'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/mongo_replica_set_client.rb:341:in `checkout_reader'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/cursor.rb:540:in `checkout_socket_from_connection'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/cursor.rb:469:in `send_initial_query'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/util/logging.rb:33:in `instrument'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/util/logging.rb:65:in `instrument'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/util/logging.rb:32:in `instrument'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/cursor.rb:466:in `send_initial_query'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/cursor.rb:451:in `refresh'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/cursor.rb:110:in `next'
      /jruby/1.9/gems/mongo-1.8.4/lib/mongo/cursor.rb:271:in `each'
      

      If you look at the code, you can clearly see it hasn't been implemented properly (I'm guessing no unit test?). The variable 'pool' is wrong, and it calls the wrong method, it should be calling 'select_near_pool' and using 'secondary_pools'
      https://github.com/mongodb/mongo-ruby-driver/blob/master/lib/mongo/util/read_preference.rb#L80

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            markmandel Mark Mandel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: