Hosting locally with high traffic - Connection Timeouts?

Error is:

Exception in setInterval callback: MongoError: connection 0 to 127.0.0.1:81 timed out

I assume that’s because I’m running: meteor --production and have about 20-50 connections at the same time. On my laptop.

This sound like the problem to any one else? I really didn’t want to have to buy another Meteor Galaxy subscription but… when success calls… right?!

Full log:

 Exception in setInterval callback: MongoError: connection 6 to 127.0.0.1:81 timed out
I20170420-21:39:02.027(-4)?     at Object.Future.wait (C:\Users\Andy\AppData\Local\.meteor\packages\meteor-tool\1.4.4_1\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:449:15)
I20170420-21:39:02.027(-4)?     at [object Object].<anonymous> (packages\meteor.js:213:24)
I20170420-21:39:02.027(-4)?     at [object Object].MongoConnection.(anonymous function) [as update] (packages/mongo/mongo_driver.js:778:49)
I20170420-21:39:02.028(-4)?     at [object Object].update (packages/mongo/collection.js:581:29)
I20170420-21:39:02.028(-4)?     at server/main.js:41:11
I20170420-21:39:02.028(-4)?     at [object Object]._.extend.forEach (packages/mongo/mongo_driver.js:1064:16)
I20170420-21:39:02.028(-4)?     at [object Object].Cursor.(anonymous function) [as forEach] (packages/mongo/mongo_driver.js:911:44)
I20170420-21:39:02.029(-4)?     at server/main.js:26:9
I20170420-21:39:02.029(-4)?     at [object Object]._.extend.withValue (packages\meteor.js:1122:17)
I20170420-21:39:02.029(-4)?     at packages\meteor.js:445:45
I20170420-21:39:02.030(-4)?     - - - - -
I20170420-21:39:02.030(-4)?     at Function.MongoError.create (C:\Users\Andy\AppData\Local\.meteor\packages\npm-mongo\2.2.24\npm\node_modules\mongodb-core\lib\error.js:29:11)
I20170420-21:39:02.031(-4)?     at Socket.<anonymous> (C:\Users\Andy\AppData\Local\.meteor\packages\npm-mongo\2.2.24\npm\node_modules\mongodb-core\lib\connection\connection.js:186:20)
I20170420-21:39:02.031(-4)?     at Socket.g (events.js:260:16)
I20170420-21:39:02.032(-4)?     at emitNone (events.js:67:13)
I20170420-21:39:02.032(-4)?     at Socket.emit (events.js:166:7)
I20170420-21:39:02.032(-4)?     at Socket._onTimeout (net.js:336:8)
I20170420-21:39:02.032(-4)?     at _runOnTimeout (timers.js:537:11)
I20170420-21:39:02.033(-4)?     at _makeTimerTimeout (timers.js:528:3)
I20170420-21:39:02.033(-4)?     at Timer.unrefTimeout (timers.js:597:5)
I20170420-21:39:35.085(-4)? t:266
I20170420-21:39:35.114(-4)? Exception from sub posts id PTexfKoXfYbBNX6go MongoError: connection 4 to 127.0.0.1:81 timed out
I20170420-21:39:35.115(-4)?     at Object.Future.wait (C:\Users\Andy\AppData\Local\.meteor\packages\meteor-tool\1.4.4_1\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:449:15)
I20170420-21:39:35.117(-4)?     at [object Object]._.extend.count (packages/mongo/mongo_driver.js:1101:51)
I20170420-21:39:35.117(-4)?     at [object Object].Cursor.(anonymous function) [as count] (packages/mongo/mongo_driver.js:911:44)
I20170420-21:39:35.118(-4)?     at [object Object]._handler (imports/posts.js:20:22)
I20170420-21:39:35.118(-4)?     at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1737:12)
I20170420-21:39:35.119(-4)?     at [object Object]._.extend._runHandler (packages/ddp-server/livedata_server.js:1035:17)
I20170420-21:39:35.119(-4)?     at [object Object]._.extend._startSubscription (packages/ddp-server/livedata_server.js:853:9)
I20170420-21:39:35.119(-4)?     at [object Object]._.extend.protocol_handlers.sub (packages/ddp-server/livedata_server.js:625:12)
I20170420-21:39:35.119(-4)?     at packages/ddp-server/livedata_server.js:559:43
I20170420-21:39:35.120(-4)?     - - - - -
I20170420-21:39:35.120(-4)?     at Function.MongoError.create (C:\Users\Andy\AppData\Local\.meteor\packages\npm-mongo\2.2.24\npm\node_modules\mongodb-core\lib\error.js:29:11)
I20170420-21:39:35.120(-4)?     at Socket.<anonymous> (C:\Users\Andy\AppData\Local\.meteor\packages\npm-mongo\2.2.24\npm\node_modules\mongodb-core\lib\connection\connection.js:186:20)
I20170420-21:39:35.120(-4)?     at Socket.g (events.js:260:16)
I20170420-21:39:35.121(-4)?     at emitNone (events.js:67:13)
I20170420-21:39:35.121(-4)?     at Socket.emit (events.js:166:7)
I20170420-21:39:35.121(-4)?     at Socket._onTimeout (net.js:336:8)
I20170420-21:39:35.121(-4)?     at _runOnTimeout (timers.js:537:11)
I20170420-21:39:35.121(-4)?     at _makeTimerTimeout (timers.js:528:3)
I20170420-21:39:35.121(-4)?     at Timer.unrefTimeout (timers.js:597:5)
I20170420-21:39:35.123(-4)? Exception in setInterval callback: MongoError: connection 0 to 127.0.0.1:81 timed out
I20170420-21:39:35.123(-4)?     at Object.Future.wait (C:\Users\Andy\AppData\Local\.meteor\packages\meteor-tool\1.4.4_1\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:449:15)
I20170420-21:39:35.123(-4)?     at [object Object].<anonymous> (packages\meteor.js:213:24)
I20170420-21:39:35.123(-4)?     at [object Object].MongoConnection.(anonymous function) [as update] (packages/mongo/mongo_driver.js:778:49)
I20170420-21:39:35.124(-4)?     at [object Object].update (packages/mongo/collection.js:581:29)
I20170420-21:39:35.126(-4)?     at server/main.js:41:11
I20170420-21:39:35.127(-4)?     at [object Object]._.extend.forEach (packages/mongo/mongo_driver.js:1064:16)
I20170420-21:39:35.127(-4)?     at [object Object].Cursor.(anonymous function) [as forEach] (packages/mongo/mongo_driver.js:911:44)
I20170420-21:39:35.127(-4)?     at server/main.js:26:9
I20170420-21:39:35.127(-4)?     at [object Object]._.extend.withValue (packages\meteor.js:1122:17)
I20170420-21:39:35.127(-4)?     at packages\meteor.js:445:45
I20170420-21:39:35.128(-4)?     - - - - -
I20170420-21:39:35.128(-4)?     at Function.MongoError.create (C:\Users\Andy\AppData\Local\.meteor\packages\npm-mongo\2.2.24\npm\node_modules\mongodb-core\lib\error.js:29:11)
I20170420-21:39:35.128(-4)?     at Socket.<anonymous> (C:\Users\Andy\AppData\Local\.meteor\packages\npm-mongo\2.2.24\npm\node_modules\mongodb-core\lib\connection\connection.js:186:20)
I20170420-21:39:35.128(-4)?     at Socket.g (events.js:260:16)
I20170420-21:39:35.129(-4)?     at emitNone (events.js:67:13)
I20170420-21:39:35.129(-4)?     at Socket.emit (events.js:166:7)
I20170420-21:39:35.129(-4)?     at Socket._onTimeout (net.js:336:8)
I20170420-21:39:35.130(-4)?     at _runOnTimeout (timers.js:537:11)
I20170420-21:39:35.130(-4)?     at _makeTimerTimeout (timers.js:528:3)
I20170420-21:39:35.130(-4)?     at Timer.unrefTimeout (timers.js:597:5)

Ahhh… You know what. I looked at what was causing the time out - and I was trying to do a

var player_ships = Posts.find({ type:"ships", owner_id: this.userId});

So, clearly, counting the entire database is bad. I changed this to findOne which should fix this issue I bet?

Having the proper indexes setup for this type of query should result in a fast search even if you use regular find

So what would be a proper index? In this case, owner_id is a Meteor.userId()

How would I fix this?

I assume that’s because I’m running: meteor --production and have about 20-50 connections at the same time. On my laptop.

I’ve done this too and ran into similar issues, running apps with the production flag or the debug flag on instead of fully compiling them will can result in similar error messages.

I don’t think the local development server is meant to handle this many connections

see: https://guide.meteor.com/deployment.html#never-use-production-flag

You would want to make sure there is either two separate indexes on the posts collection, one for type and one for owner_id or else, use a compound index that covers both fields together. The first option (two separate indexes) is more flexible, the second option is a little bit more optimized if you never query for the fields separately, only as a pair.

Ahh very nice. They should really extend that message in to the console for Meteor. Guess I’ll have to spin up another Galaxy cluster. Still, I was able to optimize the heck out of my app.

I’ve literally built an MMO on Meteor. www.StarCommanderOnline.com to check it out.

It’s not just high traffic that causes this issue. I’m getting similar errors locally and I only have 3 or 4 tabs connecting to the app. Additionally, I recently reset my db, so there aren’t that many documents (less than 20) for it to search through. I plan to add an index, but for 20ish docs, a lack of index shouldn’t cause this error

Sounds awesome :smile: Before going to Galaxy, why not try a real production build on a machine other than your dev laptop? :stuck_out_tongue: