Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js MongoDB on Ubuntu: no valid seed servers in list

I'm trying to connect to replica set from Ubuntu using this:

return when.promise(function(resolve,reject){
        new MongoClient().connect(url, {replSet: options }, function(err, db){
        console.dir(err)
        if (err)
            reject(err);

        resolve(db);
    });
});

Url looks like this:

'mongodb://mongo1.mysite.com:36108,mongo2.mysite.com:36108,mongo3.mysite.com:36108/db_config?w=0'

I'm connection to multiple databases and intermittently i see this error:

{ name: 'MongoError', message: 'no valid seed servers in list' }

And node.js crashes.

I'm kind of lost at this point. And the main problem is that it works perfectly on MAC and i see this issue only on Ubuntu. I'm on the latest mongo driver for node.js

UPDATE

I took a look at the native driver source:

http://mongodb.github.io/node-mongodb-native/core/api/replset.js.html

and found out tha error being triggered by this condition (line 987): state.initialConnectionServers == 0 && state.replState.state == CONNECTING)

Still not sure why is this happening.

like image 810
rinchik Avatar asked Nov 29 '14 21:11

rinchik


3 Answers

the difference is that you don't have a replica set on your own single mac (osx?) laptop/desktop. its running in standalone mode. but do have or intend to have a replica set on those 3 servers.

here are some potential problems with the string provided.

1) 27017 is the default port for mongo so unless it was specifically changed to 36108 that is incorrect.

mongodb://mongo1.mysite.com:36108,mongo2.mysite.com:36108,mongo3.mysite.com:36108/db_config?w=0

try

mongodb://mongo1.mysite.com:27017,mongo2.mysite.com:27017,mongo3.mysite.com:27017/db_config?w=0

2) w=0 is unfamiliar to me, perhaps its the name of your replica set. usually the connection string for replica sets is as follows, where rs0 is the name of the replicaSet.

mongodb://mongo1.mysite.com:27017,mongo2.mysite.com:27017,mongo3.mysite.com:27017/replicaSet=rs0

3) its possible you have no replica set configured. check rs.config

log into the server, mongo1.mysite.com

go into mongo shell using mongo admin -u clusteradmin -p whateverpassword

type

rs.config()

if you dont see anything like the following then you have no replica set to connect to. here rs0 is the name of the replica set. yours MIGHT be called w???

{
    "_id" : "rs0",
    "version" : 4,
    "members" : [
        {
            "_id" : 0,
            "host" : "mongo1.mysite.com:36108"
        },
        {
            "_id" : 1,
            "host" : "mongo2.mysite.com:36108"
        },
        {
            "_id" : 2,
            "host" : "mongo3.mysite.com:36108",
        }
    ]
}
  1. if that config is missing you need to add your 3 hosts into the replica set config.

rs.add("mongo1.mysite.com:36108") // or the default port with "mongo1.mysite.com:27017" rs.add("mongo2.mysite.com:36108") rs.add("mongo3.mysite.com:36108")

But better than anything is brush up o replica sets including this doc to convert a standalone to a replica set

The given /db_config string looks like a rs.config() equivalent command but done by http and expects a list of servers to add to a replica set. but frankly you cannot connect to a replica set to configure it? so that seems odd. you can connect to the primary so try

mongodb://mongo1.mysite.com:36108/db_config?w=mongo1.mysite.com:36108,mongo2.mysite.com:36108,mongo3.mysite.com:36108
like image 97
Gabe Rainbow Avatar answered Nov 18 '22 14:11

Gabe Rainbow


Increasing the amount of file descriptors solved the issue.

On Ubuntu 12.04.5 LTS default is 1024 which is not enough.

like image 1
rinchik Avatar answered Nov 18 '22 13:11

rinchik


Please follow the solutions given by rinchnik and Gabe rainbow. And if the problem still persists then please update the modules - "mongodb" to version 2.2.27+ and "mongoose" to version 4.9.1+ .

like image 1
Anshul Bisht Avatar answered Nov 18 '22 13:11

Anshul Bisht