Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-49753

Shell should provide helpful diagnostics when it fails to select a server but succeeded in discovering some servers or received an OperationFailure

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 4.4.0-rc12
    • Fix Version/s: Backlog
    • Component/s: None
    • Labels:
      None

      Description

      I attempted to connect to a deployment using mongo shell and received the following output:

      serene% mongo 'mongodb+srv://U:P@cluster0.kiwls.mongodb.net/mydb123?retryWrites=true&w=majority'          
      MongoDB shell version v4.4.0-rc12
      connecting to: mongodb://cluster0-shard-00-00.kiwls.mongodb.net:27017,cluster0-shard-00-01.kiwls.mongodb.net:27017,cluster0-shard-00-02.kiwls.mongodb.net:27017/mydb123?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=atlas-wpf52v-shard-0&retryWrites=true&ssl=true&w=majority
      {"t":{"$date":"2020-07-21T01:48:47.334Z"},"s":"I",  "c":"NETWORK",  "id":4333208, "ctx":"ReplicaSetMonitor-TaskExecutor","msg":"RSM host selection timeout","attr":{"replicaSet":"atlas-wpf52v-shard-0","error":"FailedToSatisfyReadPreference: Could not find host matching read preference { mode: \"primary\", tags: [ {} ] } for set atlas-wpf52v-shard-0"}}
       
       
      *** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.
       
      Error: Could not find host matching read preference { mode: "primary", tags: [ {} ] } for set atlas-wpf52v-shard-0 :
      connect@src/mongo/shell/mongo.js:362:17
      @(connect):2:6
      exception: connect failed
      exiting with code 1
      

      This output says:

      • Very prominently - that there may be a whitelist issue
      • Less prominently - that it failed to find a host matching read preference (which to a beginner user says nothing)

      Given this output, one might try to fix the whitelist but the problem is not at all in network connectivity, but rather there is some kind of an internal issue with this deployment.

      The error that the Ruby driver, for example, produces when trying to connect to this deployment is:

      Mongo::Error::NoServerAvailable (No primary server is available in cluster: #<Cluster topology=ReplicaSetNoPrimary[cluster0-shard-00-00.kiwls.mongodb.net:27017,cluster0-shard-00-01.kiwls.mongodb.net:27017,cluster0-shard-00-02.kiwls.mongodb.net:27017,name=atlas-wpf52v-shard-0] servers=[#<Server address=cluster0-shard-00-00.kiwls.mongodb.net:27017 SECONDARY replica_set=atlas-wpf52v-shard-0 pool=#<ConnectionPool size=0 (0-5) used=0 avail=0 pending=0>>,#<Server address=cluster0-shard-00-01.kiwls.mongodb.net:27017 UNKNOWN>,#<Server address=cluster0-shard-00-02.kiwls.mongodb.net:27017 SECONDARY replica_set=atlas-wpf52v-shard-0 pool=#<ConnectionPool size=0 (0-5) used=0 avail=0 pending=0>>]> with timeout=30, LT=0.015)
      

      (Full log: https://gist.github.com/p-mongo/06d779ac56d403d4833aa845994d77f8)

      From this error one can clearly see that the deployment has two secondaries and no primary, therefore the issue is not the ip whitelist.

      I see that the shell also has a --verbose option which provides much more log output than the Ruby driver does and in this output you can see some of the responses succeeding. Still the error message can be improved to not suggest ip whitelist as a possible cause when it is not in fact a possible cause.

      (via https://stackoverflow.com/questions/63006012/trying-to-connect-cluster-to-application#63006012)

        Attachments

          Activity

            People

            Assignee:
            backlog-server-servicearch Backlog - Service Architecture
            Reporter:
            oleg.pudeyev Oleg Pudeyev
            Participants:
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated: