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

Do not auto-detect replica members when server bound to localhost

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

       

      In the Mongo::Cluster::SdamFlow class, the Mongo Ruby Driver has logic to auto-detect replica set members when the differ from your host config (e.g. in mongoid.yml.)

      Usually this is great, but there are cases where one would not want this logic. The case I am encountering is:

      • I'm running MongoDB server of my dev machine ("Machine A") bound to localhost (127.0.0.1)
      • I'm using replica set topology
      • I'm using a local tunnel proxy (e.g. ngrok) for testing purposes
      • I run Rails with MONGODB_HOSTS=mongodb://0.tcp.ngrok.io:16059 on an external machine ("Machine B")

      1. The driver removes my defined host:

      WARN -- : MONGODB | Removing server 0.tcp.ngrok.io:16059 because it is not in hosts reported by primary 0.tcp.ngrok.io:16059 (self-identified as 127.0.0.1:27017). Reported hosts are: 127.0.0.1:27017

      2. The driver then adds the self-declared "localhost" to the topology. This results in the driver attempting to connect to a mongod instance on the external localhost ("Machine B"), which doesn't exist.

       

      WARN -- : MONGODB | Error checking 127.0.0.1:27017: Mongo::Error::SocketError: Errno::ECONNREFUSED: Connection refused - connect(2) for 127.0.0.1:27017 (for 127.0.0.1:27017 (no TLS)) (on 127.0.0.1:27017) 
      

       

      Workaround

      I was able to resolve this with the following monkey patch:

      class Mongo::Cluster::SdamFlow
        def add_servers_from_desc(_)
          []
        end
      
        def remove_servers_not_in_desc(_)
        end
      end

       

      How to Improve

      **I think it would be safe to skip the add_servers_from_desc / remove_servers_not_in_desc logic in the case that the a single mongod instance bound to localhost is detected. Would like to hear opinions on this.

      It would also be fine to add a config option, which hopefully could be passed in via mongoid.yml.

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: