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

cluster mode standalone servers erroneously returns array containing nil

    • 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

      Mongo::Cluster::Mode::Standalone.servers erroneously returns [nil] if the configuration is empty, for example, before cluster.servers.scan! or when the server is down and cluster.servers.scan! is run.

      The current code is:

      module Mongo
        class Cluster
          module Mode
            class Standalone
              def self.servers(servers, name = nil)
                [ servers.detect{ |server| server.standalone? } ]
              end
            end
          end
        end
      end
      

      Enumerable#detect returns nil if there is no match, which causes other complicated errors up the call chain, for example in Mongo::ServerPreference::Selectable#primary. It smells like a definite bug since Enumerable#select would be better, although other issues still exist up the chain.

      The following is a possible improvement, with a check for now to catch other errors that have occurred, for example with a standalone client connecting to a single member of a replica set.

      module Mongo
        class Cluster
          module Mode
            class Standalone
              def self.servers(servers, name = nil)
                raise "#{self.name}.#{__method__}: only one server expected, servers: #{servers.inspect}" if servers.size != 1
                servers
              end
            end
          end
        end
      

      An alternative would be to somehow make Mongo::Server::Description#standalone mode aware.

            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: