MongoError: no primary found in replicaset (Mongoose replaces external IP addresses on gcloud with internal addresses)

1.2k views Asked by At

(cross-posting https://github.com/Automattic/mongoose/issues/4834)

This is the latest version of mongodb - 3.4.0 (mongo:latest from docker) and I have installed a mongo cluster on google compute engine. Each mongo server has an external and an internal IP address.

I can connect to individual mongo nodes using the same nodejs code. But when I club both the IP addresses ( mongodb://IP-ADDR1,IP-ADDR2 ) I get 'no primary found error'.

From the logs it looks like, mongodb connects to each of the server in URL and fetches a topology related datastructure (ismaster) as below,

ismaster [{"hosts":["10.60.4.5:27017","10. 60.4.6:27017"],"setName":"rs0","setVersion":4,"ismaster":false,"secondary":true,"primary":"10.60.4.5:27017","me":"10. 60.4.6:27017","lastWrite":{"opTime":{"ts":"6367309576328445953","t":1},"lastWriteDate":"2016-12-23T14:53:07.000Z"},"m axBsonObjectSize":16777216,"maxMessageSizeBytes":48000000,"maxWriteBatchSize":1000,"localTime":"2016-12-23T14:53:13.7 21Z","maxWireVersion":5,"minWireVersion":0,"readOnly":false,"ok":1}]

Here it sees that ismaster.me is not same as the IP-ADDR used to call the connect command with (the ismaster.me is the internal IP address). Following which, mongo removes the original IP-Address from seedlist, Like below:

[WARN-ReplSet:9532] 1482504793904 the seedlist server was removed due to its address 104.197.115.7:27017 not matching its ismaster.me address 10.60.4.6:27017 { type: 'warn'

Finally this results in 'no primary found in replicaset'

Longer log details are posted at the link - https://github.com/Automattic/mongoose/issues/4834

TIA.

Please let me know if my analysis is correct and if we are aware of a workaround to the problem.

1

There are 1 answers

0
navalsaini On

Received response from Mongodb nodejs native driver team (via Christian Amor Kvalheim).

This is expected behavior the replicaset configuration is the canonical source for the replicaset and is the one used by the driver to connect to, monitor and discover new members. If you are not making those resolvable you will need to modify the host files to include them for local dns resolution.

http://mongodb.github.io/node-mongodb-native/2.2/reference/faq/