No primary server available when failover happens: MongoDB, Node.js, Mongoose

389 views
Skip to first unread message

Astro

unread,
Jul 6, 2016, 6:07:34 AM7/6/16
to mongodb-user

I am currently facing an issue when failover happens in mongodb replica set. The app fails to reconnect to the newly elected primary server and fails to perform all subsequent write operations.


Restarting app reconnects successfully.


The failover happens instantly and a new primary is elected. However, the app fails to connect to the new primary.


mongodb version: 3.2.6

 mongoose version: 3.4.3

 node.js version:0.10.26


Any help will be appreciated.


Kevin Adistambha

unread,
Jul 13, 2016, 2:18:44 AM7/13/16
to mongodb-user

Hi,

I am currently facing an issue when failover happens in mongodb replica set. The app fails to reconnect to the newly elected primary server and fails to perform all subsequent write operations.

mongodb version: 3.2.6


mongoose version: 3.4.3
node.js version:0.10.26

You may have an outdated version of mongoose and MongoDB node.js driver. MongoDB 3.2.x is currently supported by mongoose version 4.3.0 and above, and node.js driver version 2.1.0 and above. Please see:

Also, please ensure that the connection string references a replica set (e.g: mongodb://server1:27017,server2:27017,server3:27107/dbname?replicaSet=set)

Best regards,
Kevin

Astro

unread,
Jul 13, 2016, 2:55:14 AM7/13/16
to mongodb-user

Thanks Kevin,


 Just a quick update:

The mongoose version we're using is 4.3.4 and mongodb node.js version is 2.1.2.

The connection string is properly formed.

Any other suggestions?


Kevin Adistambha

unread,
Jul 13, 2016, 3:21:55 AM7/13/16
to mongodb-user

Hi,

The mongoose version we’re using is 4.3.4 and mongodb node.js version is 2.1.2.
The connection string is properly formed.
Any other suggestions?

You may want to try setting mongoose debug flag: mongoose.set('debug', true) and see what is happening during failover.

I cannot seem to reproduce the issue you are seeing (i.e. my test application could consistently reconnect to a new Primary after a short time). It will be helpful if you can post a short, self-contained code that could consistently reproduce this problem.

Best regards,
Kevin

Astro

unread,
Sep 2, 2016, 6:03:33 AM9/2/16
to mongodb-user

The issue seems to be resolved when the hostnames in replica set are repliced with corresponding host ip addresses.

When the replica set reconfigured with adding members using ip address instead of host names as:

rs.add("111.22.33.44:2170") instead of rs.add("mongo-server-2:27017").

The application connects to newly elected primary whenever failover happens.

Is that related to any issue in mongoose which fails to resolve the ips against hostnames?

PS: ips of the mongodb replica set were provided in app config. 
Reply all
Reply to author
Forward
0 new messages