Closed ChrisZieba closed 8 years ago
Do you see it possible/likely that the massive amounts of disconnect/reconnect can intermittently cause the no primary server available issue?
yes as there will be a brief period where there might not be any servers in the set
@christkv I've been waiting until this happens again to send you some logs in that other ticket. Our cluster has actually been stable for the last few weeks and we have not seen this error.
@ChrisZieba funny how that always seems to happen lol :+1: I'Il leave the ticket open in jira for now and see what we can figure out.
@christkv Hi Christian, i'm just curious if you have any pointers on workarounds in the case of lower traffic. I was thinking of just reducing the pool size as well as increasing the timeouts.
if it helps anyone else, I removed the socket timeout as well as increased keepAlive to 200 and also reduced the poolsize to 3.. i seem to have a lot less disconnect/reconnects.. however it does still occasionally happen.
If it helps anyone, we removed almost all mongoose settings, including socketTimeout and connectionTimeout and keepAlive and connections started to be stable. Our poolSize is 200. I'm not sure it's the recommended approach but it works now. We're still monitoring it to make sure it holds.
mongoose v4.4.2 Node 4 Mongo 3.0
Do you have a huge amount of slow operations ? if you don't I don't think you will notice any difference between a pool of 20 sockets vs 500.
Sorry... it's 200. Fixed the comment.
And yeah, you're right. We don't sense much difference but we rather have the pool size larger than smaller.
The real problem with when connections keep opening and not closed. This used to happen until we removed all mongoose timeout and keepAlive settings. I wonder why these are handled by mongoose/mongo-driver and not letting the OS do it?
Well 2.1.7 and higher has a redesigned pool that avoid this. If you set socketTimeout 0 you delegate it to the os but that might be as much as 10 minutes of hanging connections.
Ok. interesting. So now that I removed the keepAlive and socketTimeout settings what are the default settings?
it depends, not sure if mongoose set any specific settings as default. if you use the MongoClient.connect method in the driver it's 30 seconds for both connect and socket timeouts.
We do use connect
but when we set 30 secs manually connections starting to pile up.
Well with 500 connections you need at least 500 ops inside the socketTimeout period to keep the pool open, otherwise it will close down and force a reconnect. This changes in 2.1.7 however as the pool is a growing/shrinking model.
I am having same issue with mongodb 3.2.6 and mongoose 4.3.4. Any help on this?
@15astro try to remove the settings of socketTimeout
and connectionTimeout
and see if it helps.
@refaelos Ok..willl try that..I tried with keepAlive=6000 but that didn't help. Just wanted to know how removingsocketTimeout
and connectionTimeout
will help?
Yeah we tried it with different values and only when we completely removed these settings things started to work well.
@refaelos: I found no luck with removing these settings. Any other thing I am missing?
@15astro no man. Sorry. This is how our settings looks like today:
mongo : {
uri : process.env.MNG_URL || 'mongodb://localhost/myDB',
options: {
user : process.env.MNG_USER,
pass : process.env.MNG_PASS,
replset: {
poolSize: 200
}
}
}
In my case it was related to lack of IP to name binding in /etc/hosts.
If you have set up replica set with names instead of IPs and you have something like this in /etc/hosts of MongoDB nodes:
10.10.10.10 mongodb-2gb-fra1-02 10.10.10.11 mongodb-2gb-fra1-01 10.10.10.12 mongodb-2gb-fra1-03
Then you also need to put it in /etc/hosts of all your app servers.
I thought that node-mongo connects according to whatever I put in the URI, but it's not the case.
It seems that node-mongo connects by IP or name from Mongo URI, then gets hostnames of other replica members from the first MongoDB node that responded to request. It gets for example mongodb-2gb-fra1-03
and passes it to OS for resolving. If OS doesn't know anything about mongodb-2gb-fra1-03
, it throws "Error no primary server available".
Hope that helps.
@adriank yes that's correct it bases it's connections of the ones it gets back from the replicaset config. The reason is that this is the canonical source of truth about a replicaset. This is also why all addresses in the replicaset configuration must be resolvable by the driver for the driver to failover correctly and for it to be able to detect servers being added and removed from the set. Previous drivers did not implement the SDAM spec and where more lax. This however would cause problems in production environments.
@christkv However it is a nightmare for tools like our MongoSpector. Because of it we have problems with connecting securely to more than one replica from one host. DigitalOcean auto-generates names to droplets that almost nobody changes and the effect is that many clients have mongodb-2gb-fra1-01
as their PRIMARY. :) I hope we can figure something out.
We are tracking a server ticket here https://jira.mongodb.org/browse/SERVER-1889. I would love for something like this to be possible.
We should also file a ticket with DigitalOcean pointing out the mistake they are making and how it's affecting their users.
by the way you can remove and re-add the replicaset members with their new names being ips
Having a similiar issue, after around 12-24hours of being connected our we get an error "No primary server available"
Restarting usually fixes the issue.
connection:
{ "url": "mongodb://user:password@cluser-shard-00-00, cluser-shard-00-01, cluster-shard-00-02/settings?ssl=true&replicaSet=primarycluster-shard-0&authSource=admin&retryWrites=true", "options": { "db": { "w": 1, "wtimeout": 3000, "fsync": true }, "authSource": "admin", "server": { "poolSize": 3, "socketOptions": { "autoReconnect": true, "keepAlive": 60000, "connectTimeoutMS": 7000, "socketTimeoutMS": 15000 } } }, "password": "password", "username": "username" }
We added &readPreference=secondaryPreferred
this reduced the operations on primary and we did't get no primary found error anymore. This could be a temporary fix for us once there are more number of write operation i believe this might happen again.
MongoClient Version used 3.5
I have an issue that is rather difficult to debug, and was wondering if anyone sees anything wrong with my configuration.
Nodejs version
4.2.1
and mongoDB version3.0.7
with mongoose4.2.8
.This seems to happen randomly and will open many connection until I finally restart the node process. The cluster is healthy at all times during this error. This error happens hundreds of times per hour. There does not seem to be any consistency as to when the error will begin. For example, it occurs when the cluster is operating normally and no changes to the primary have been made.
This is what the db stats look like. As you can see the number of connections will steadily increase. If I kill the node process and start a new one everything is fine.
Config
Connection String
Stack trace