ReplicaSet Timeout

SUMMARY: Recently worked on the replica set and it was successfully able to connect from compass using the connection string below

mongodb://10.47.72.28:27017,10.47.72.38:27017,10.47.72.39:27017?replicaSet=mongo-cluster.

ISSUE: Post enabling the authentication, I cannot connect as cluster (connect ETIMEDOUT ) but can connect individually . Below is the connection string and authentication entry.

mongodb://admin:Admin%40123@10.47.72.28:27017,10.47.72.38:27017,10.47.72.39:27017/?authSource=admin&replicaSet=mongo-cluster&readPreference=primaryPreferred&appname=MongoDB%20Compass&ssl=false

Strangely I can connect to all the nodes individually without opting replicaSet in compass. Can someone please advise on what could be happening here.

monogd.cnf values 

net:
  port: 27017
  bindIp: 0.0.0.0  

security:
  authorization: enabled
  keyFile: /etc/mongo/mongodb.key

replication:
 replSetName: mongo-cluster
 enableMajorityReadConcern: true*

Below are the logs

{"t":{"$date":"2021-12-05T18:27:19.258+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"13.126.136.66:64175","connectionId":202,"connectionCount":15}}
{"t":{"$date":"2021-12-05T18:27:19.260+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn202","msg":"client metadata","attr":{"remote":"13.126.136.66:64175","client":"conn202","doc":{"driver":{"name":"nodejs","version":"4.0.0-beta.6"},"os":{"type":"Windows_NT","name":"win32","architecture":"x64","version":"10.0.19044"},"platform":"Node.js v12.4.0, LE (unified)|Node.js v12.4.0, LE (unified)","application":{"name":"MongoDB Compass"}}}}
{"t":{"$date":"2021-12-05T18:27:19.306+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn202","msg":"Connection ended","attr":{"remote":"13.126.136.66:64175","connectionId":202,"connectionCount":14}}

ReplicaSet Config.

rs.config()

{ “_id” : “mongo-cluster”, “version” : 3, “term” : 19, “protocolVersion” : NumberLong(1), “writeConcernMajorityJournalDefault” : true, “members” : [ { “_id” : 0, “host” : “174.1.0.6:27017”, “arbiterOnly” : false, “buildIndexes” : true, “hidden” : false, “priority” : 1, “tags” : {

                    },
                    "slaveDelay" : NumberLong(0),
                    "votes" : 1
            },
            {
                    "_id" : 1,
                    "host" : "174.1.0.7:27017",
                    "arbiterOnly" : false,
                    "buildIndexes" : true,
                    "hidden" : false,
                    "priority" : 1,
                    "tags" : {

                    },
                    "slaveDelay" : NumberLong(0),
                    "votes" : 1
            },
            {
                    "_id" : 2,
                    "host" : "174.1.0.8:27017",
                    "arbiterOnly" : false,
                    "buildIndexes" : true,
                    "hidden" : false,
                    "priority" : 1,
                    "tags" : {

                    },
                    "slaveDelay" : NumberLong(0),
                    "votes" : 1
            }
    ],
    "settings" : {
            "chainingAllowed" : true,
            "heartbeatIntervalMillis" : 2000,
            "heartbeatTimeoutSecs" : 10,
            "electionTimeoutMillis" : 10000,
            "catchUpTimeoutMillis" : -1,
            "catchUpTakeoverDelayMillis" : 30000,
            "getLastErrorModes" : {

            },
            "getLastErrorDefaults" : {
                    "w" : 1,
                    "wtimeout" : 0
            },
            "replicaSetId" : ObjectId("618a54b988498045e01e33ee")
    }

} mongo-cluster:PRIMARY>

The IP addresses used to connect using the replica set options do not match the IP addresses of your rs.config().

Hi Steevej,
Thanks for the response. The Ip Addresses were correct.
I tried connecting from compass using public ip… whereas within the cluster the connection happens using private IPs

 mongo-cluster:PRIMARY> rs.status()
    {
            "set" : "mongo-cluster",
            "date" : ISODate("2021-12-06T11:00:23.263Z"),
            "myState" : 1,
            "term" : NumberLong(19),
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "heartbeatIntervalMillis" : NumberLong(2000),
            "majorityVoteCount" : 2,
            "writeMajorityCount" : 2,
            "votingMembersCount" : 3,
            "writableVotingMembersCount" : 3,
            "optimes" : {
                    "lastCommittedOpTime" : {
                            "ts" : Timestamp(1638788417, 1),
                            "t" : NumberLong(19)
                    },
                    "lastCommittedWallTime" : ISODate("2021-12-06T11:00:17.347Z"),
                    "readConcernMajorityOpTime" : {
                            "ts" : Timestamp(1638788417, 1),
                            "t" : NumberLong(19)
                    },
                    "readConcernMajorityWallTime" : ISODate("2021-12-06T11:00:17.347Z"),
                    "appliedOpTime" : {
                            "ts" : Timestamp(1638788417, 1),
                            "t" : NumberLong(19)
                    },
                    "durableOpTime" : {
                            "ts" : Timestamp(1638788417, 1),
                            "t" : NumberLong(19)
                    },
                    "lastAppliedWallTime" : ISODate("2021-12-06T11:00:17.347Z"),
                    "lastDurableWallTime" : ISODate("2021-12-06T11:00:17.347Z")
            },
            "lastStableRecoveryTimestamp" : Timestamp(1638788417, 1),
            "electionCandidateMetrics" : {
                    "lastElectionReason" : "stepUpRequestSkipDryRun",
                    "lastElectionDate" : ISODate("2021-12-02T07:02:16.093Z"),
                    "electionTerm" : NumberLong(19),
                    "lastCommittedOpTimeAtElection" : {
                            "ts" : Timestamp(1638428533, 1),
                            "t" : NumberLong(18)
                    },
                    "lastSeenOpTimeAtElection" : {
                            "ts" : Timestamp(1638428533, 1),
                            "t" : NumberLong(18)
                    },
                    "numVotesNeeded" : 2,
                    "priorityAtElection" : 1,
                    "electionTimeoutMillis" : NumberLong(10000),
                    "priorPrimaryMemberId" : 1,
                    "numCatchUpOps" : NumberLong(0),
                    "newTermStartDate" : ISODate("2021-12-02T07:02:16.106Z"),
                    "wMajorityWriteAvailabilityDate" : ISODate("2021-12-02T07:02:18.107Z")
            },
            "members" : [
                    {
                            "_id" : 0,
                            "name" : "174.1.0.6:27017",
                            "health" : 1,
                            "state" : 1,
                            "stateStr" : "PRIMARY",
                            "uptime" : 427920,
                            "optime" : {
                                    "ts" : Timestamp(1638788417, 1),
                                    "t" : NumberLong(19)
                            },
                            "optimeDate" : ISODate("2021-12-06T11:00:17Z"),
                            "syncSourceHost" : "",
                            "syncSourceId" : -1,
                            "infoMessage" : "",
                            "electionTime" : Timestamp(1638428536, 1),
                            "electionDate" : ISODate("2021-12-02T07:02:16Z"),
                            "configVersion" : 3,
                            "configTerm" : 19,
                            "self" : true,
                            "lastHeartbeatMessage" : ""
                    },
                    {
                            "_id" : 1,
                            "name" : "174.1.0.7:27017",
                            "health" : 1,
                            "state" : 2,
                            "stateStr" : "SECONDARY",
                            "uptime" : 359881,
                            "optime" : {
                                    "ts" : Timestamp(1638788417, 1),
                                    "t" : NumberLong(19)
                            },
                            "optimeDurable" : {
                                    "ts" : Timestamp(1638788417, 1),
                                    "t" : NumberLong(19)
                            },
                            "optimeDate" : ISODate("2021-12-06T11:00:17Z"),
                            "optimeDurableDate" : ISODate("2021-12-06T11:00:17Z"),
                            "lastHeartbeat" : ISODate("2021-12-06T11:00:21.530Z"),
                            "lastHeartbeatRecv" : ISODate("2021-12-06T11:00:21.530Z"),
                            "pingMs" : NumberLong(0),
                            "lastHeartbeatMessage" : "",
                            "syncSourceHost" : "174.1.0.6:27017",
                            "syncSourceId" : 0,
                            "infoMessage" : "",
                            "configVersion" : 3,
                            "configTerm" : 19
                    },
                    {
                            "_id" : 2,
                            "name" : "174.1.0.8:27017",
                            "health" : 1,
                            "state" : 2,
                            "stateStr" : "SECONDARY",
                            "uptime" : 359879,
                            "optime" : {
                                    "ts" : Timestamp(1638788417, 1),
                                    "t" : NumberLong(19)
                            },
                            "optimeDurable" : {
                                    "ts" : Timestamp(1638788417, 1),
                                    "t" : NumberLong(19)
                            },
                            "optimeDate" : ISODate("2021-12-06T11:00:17Z"),
                            "optimeDurableDate" : ISODate("2021-12-06T11:00:17Z"),
                            "lastHeartbeat" : ISODate("2021-12-06T11:00:21.534Z"),
                            "lastHeartbeatRecv" : ISODate("2021-12-06T11:00:21.530Z"),
                            "pingMs" : NumberLong(0),
                            "lastHeartbeatMessage" : "",
                            "syncSourceHost" : "174.1.0.7:27017",
                            "syncSourceId" : 1,
                            "infoMessage" : "",
                            "configVersion" : 3,
                            "configTerm" : 19
                    }
            ],
            "ok" : 1,
            "$clusterTime" : {
                    "clusterTime" : Timestamp(1638788417, 1),
                    "signature" : {
                            "hash" : BinData(0,"UeCHJX2kYRT5awReraDGQBMt13E="),
                            "keyId" : NumberLong("7028523322010763269")
                    }
            },
            "operationTime" : Timestamp(1638788417, 1)
    }

mongo-cluster:PRIMARY>