[SERVER-49753] Shell should provide helpful diagnostics when it fails to select a server but succeeded in discovering some servers or received an OperationFailure Created: 21/Jul/20  Updated: 06/Dec/22  Resolved: 24/Feb/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 4.4.0-rc12
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Oleg Pudeyev (Inactive) Assignee: Backlog - Service Architecture
Resolution: Won't Do Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Service Arch
Participants:

 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)



 Comments   
Comment by Lauren Lewis (Inactive) [ 24/Feb/22 ]

We haven’t heard back from you for at least one calendar year, so this issue is being closed. If this is still an issue for you, please provide additional information and we will reopen the ticket.

Comment by Oleg Pudeyev (Inactive) [ 16/Aug/20 ]

The shell also suggests IP whitelist check on auth failure:

serene% mongo "mongodb+srv://cluster0.vkqlr.mongodb.net/test" --username x            
MongoDB shell version v4.4.0
Enter password: 
connecting to: mongodb://cluster0-shard-00-01.vkqlr.mongodb.net:27017,cluster0-shard-00-02.vkqlr.mongodb.net:27017,cluster0-shard-00-00.vkqlr.mongodb.net:27017/test?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=atlas-taomc9-shard-0&ssl=true
 
 
*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.
 
Error: can't connect to new replica set master [cluster0-shard-00-02.vkqlr.mongodb.net:27017], err: AuthenticationFailed: Authentication failed. :
connect@src/mongo/shell/mongo.js:362:17
@(connect):2:6
exception: connect failed
exiting with code 1

If authentication failed (or any OperationFailure was received for that matter), the problem cannot be a whitelist issue.

Generated at Thu Feb 08 05:20:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.