mongoose: 4.7.1 => 4.7.2 : MongoError connection timed out
When testing mongoose@4.7.2 / mongodb@2.2.12, I get:
MongoError: connection 2 to XXXXXX timed out at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:29:11) at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:186:20) at Socket.g (events.js:286:16) at emitNone (events.js:86:13) at Socket.emit (events.js:185:7) at Socket._onTimeout (net.js:333:8) at tryOnTimeout (timers.js:224:11) at Timer.listOnTimeout (timers.js:198:5)’ } 'connection 2 to XXXXXX timed out
this does not happen with mongoose@4.7.1 / mongodb@2.2.11.
More details:
- query: aggregate with allowDiskUse(true).read(‘secondaryPreferred’).cursor()
- timing: the error happens about 35s after sending the query (before first results are received)
- node version: v6.3.0
- npm version: 3.10.9
- connect options:
{
"socketOptions": {
"socketTimeoutMS": 240000,
"keepAlive": 10000,
"connectTimeoutMS" : 30000
}
- query:
[
{ $match: {
_id: { $lt: oid },
signature: { $exists: true }
}
},
{ $group: {
_id: { myid: '$myid', signature: '$signature' },
count: { $sum: 1 },
myid: { $first: '$myid' },
docs: { $push: { _id: '$_id', name: '$name' } }
}
},
{ $match: {
count: { $gt : 1 }
}
}
]
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 44 (2 by maintainers)
The issue has been unresolved for some time now. What should we do to fix this? At some point I would like to update to the recent version but I can only do that when this has been resolved.
I was also having the same issue with
mongo 3.6.2
andmongoose 4.9.2
I fixed it by passing additional connection parametersMONGO_URI=mongodb://user:password@127.0.0.1:27017/dbname?keepAlive=true&poolSize=30&autoReconnect=true&socketTimeoutMS=360000&connectTimeoutMS=360000
Not sure if this helps anyone, but in our case we noticed that we were passing in our timeout params (
socketTimeoutMS
etc) in throughoptions.server
. This was wrong! We are using a replica set and as such our options should have as below:In our case the application actually needed the ability to connect to either a replica or normal server, so we did:
Hope that helps someone!
I think there may be more to this issue than meets the eye. I’ve had to revert to 4.4.20 to completely stop these aggregate timeouts occurring under all circumstances. 4.7.x and 4.6.x both had bogus very quick timeouts under some circumstances of multiple concurrent executions. I skipped 4.5 and went straight back to a known good version (4.4.20) which we are using in production, and that has completely solved the problem, but TBH I’m still mystified by what is happening. I’m sorry I don’t have any further data to add, but I’m not sure if it is solely a problem with the version of the native mongodb driver that mongoose is using, or if there’s more than one contributory factor at work.
I’m experiencing the same problem, mongoose@4.7.4, mongodb@2.2.16
Rolling back to mongoose@4.7.1 / mongodb@2.2.11 solves the issue, i.e., does not cause timeouts
From mongodb@2.2.11 to 2.2.12 the timeout event listener changed from “once” to “on”, maybe this has something to do with it?
Or should we post this as an issue in the mongodb native driver?
In case it helps anyone, I experienced this issue when parallelizing 2 brutal
find()
queries (using Promise pattern).Turning
into a sequential approach
Made it work
Same here with:
mongo version @ 3.2.11
on AWS EC2.
Any update/workaround? Would
keepAlive: true
have any positive effect?mongodb@2.2.17 updated to mongodb-core@2.1.3 which includes a fix for monitoring operations timing out and generating a timeout event on running operations @1284917
Soon Mongoose updates to mongodb@2.2.19, I will give it a try.
@silentjohnny Getting the same issue with mongoose@4.7.4
For those experiencing the intermittent errors, I had those too on mongoose-4.13.11 with mongodb-2.2.35 mongodb-core-2.1.19 in a particular environment. Various queries at different points in our testsuite, though mostly testing one particular part of our app which has heavier queries and does do things in parallel IIRC, were all getting this error message. And the whole test suite does not even take 15s to run, so there’s no way I should have been hitting the built-in default 30s timeouts in the first place:
This only happened in our CI test build server. I couldn’t reproduce it on my dev machine.
(In my own system (private repo, this is for my own reference in case ever need to dig this up again), this error shows up at least in build numbers are 358, 356, 355, 352).
After turning on
useMongoClient: true
, the tests seem to pass reliably in the CI environment so far. I have had three successful runs with just that change whereas many prior sequential runs fail due to the weird timeout error.I think @thenitai @steve-p-com @adrienbaron were experiencing the weird bogus timeouts too. I think the error was happening to you guys before 4.11 was out which even brought
useMongoClient: true
as an option. Can you tell if that made the difference for your workloads?@MinhNguyen41092 right now the only docs are the MongoDB driver docs http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#connect . we’ll add details about this to http://mongoosejs.com/docs/connections.html
@cyrilchapon thought it was working for me but your sequential approach did not solve my issue 😕
it is intermittent… sometimes it works, sometimes it times out…
Hello Everyone, I am using mlab to host my database. I get this error Mongo DB connectionerror: {[MongoError: connection 0 to ds155841.mlab.com:xxxxx timed out’}
I’m seeing this issue too on my server with Mongoose
4.7.7
, MongoDB3.4.1
and Node4.7.2
. When memory usage is high on my server, timeouts seems to occur randomly in series:As you can see the requests none of the request lasted more than 12s. My mongoose connector is set up this way:
Any idea what could be going wrong?
mongoose@4.7.7 seems to have solved the timeouts for me. @steve-p-com like you are suggesting, the timeouts in 4.7.2 were indeed bogus and caused error events being emitted on the wrong connection, this was solved by mongodb-core@2.1.6 and so mongoose@4.7.7 should work fine in your case. Did you run a test with that version?
Haven’t tested 4.7.9 or 4.8.0 yet, maybe mongodb@2.2.22 introduced a regression, which would explain the issue @flosky is experiencing. Does that timeout also happen on mongoose@4.7.7?
I’m certain the timeouts are often bogus. In one scenario I was looking at I started four simultaneous aggregate.exec operations which take around 30 seconds. One timed out in 8 seconds, one timed out in 20 seconds, but the other two completed normally in 30 seconds. Repeating caused a different timeout order, but always a similar result. I suspect timeouts are incorrectly being set on the wrong connections, or are not being removed when an operation completes so that they fire unexpectedly on a subsequent exec. Something like that anyway. Unfortunately I’ve no time at the moment to pursue it.
Having the same problem with mongoose@4.7.9 and mongodb@2.2.22. Timeouts are really weird. This one is pretty short (around 5s) and very reproducible but other queries take longer than 5s and do not time out