Server Timed Out?

55 views
Skip to first unread message

Max Ehrlich

unread,
May 23, 2016, 7:53:30 AM5/23/16
to node-mongodb-native
I have a large number of tweets stored in a MongoDB database and I am connecting with the nodejs driver version 2.1.19.

No matter what I do I am getting 
MongoError: server xxxxxxxxxx timed out


I have tried calling the query using 
let cursor = db.collection(program.collection).find({
            entities: {
                media: {
                    $elemMatch: {
                        $or: [
                            { type: 'video' },
                            { type: 'photo' }
                        ]
                    }
                }
            }
        }).addCursorFlag('noCursorTimeout',true);

and I have 
MongoClient.connect(url, {
            promiseLibrary: Promise,
            server: {
                socketOptions: {
                    connectTimeoutMs: 0,
                    socketTimeoutMs: 0
                }
            }
        })

but still I get this timeout error. Can you tell me how to disable the timeout?

Christian Kvalheim

unread,
May 23, 2016, 8:12:59 AM5/23/16
to node-mongodb-native
Set the timeout on the connection string. Also how long does the query actually take to run ?

Max Ehrlich

unread,
May 23, 2016, 9:07:49 AM5/23/16
to node-mongodb-native
I'm not sure how long it takes to run I've never gotten it to work successfully , I will probably get my server team to create some indexes but in the meantime I wanted this to work for some testing.

I'm seeing a lot of different timeout settings in the connection string documentation and they all claim that the default is to never timeout, I'll try setting them all to zero but is there any particular one I should be setting? Also do you know why they are timing out when the documentation says it shouldnt be?

Christian Kvalheim

unread,
May 23, 2016, 9:40:42 AM5/23/16
to node-mongodb-native
Don't set it to zero (zero does not mean for ever. It means to delegate the timeout to the operating system). Set it to some very high value.

Max Ehrlich

unread,
May 23, 2016, 10:04:51 AM5/23/16
to node-mongodb-native
So there is no way to completely disable the timeout?

Christian Kvalheim

unread,
May 23, 2016, 10:08:34 AM5/23/16
to node-mongodb-native
Not really you can set a high value but eventually the os will timeout. To change the os default timeout you would have to lookup it up separately.

I would definitively suggest an index for quicker retrieval.

Max Ehrlich

unread,
May 23, 2016, 10:18:51 AM5/23/16
to node-mongodb-native
Ok thanks, I'll just go straight for the index instead of trying to make this work

Max Ehrlich

unread,
May 23, 2016, 2:08:39 PM5/23/16
to node-mongodb-native
Ok I created the index and I'm using the following connection string:

let url = `mongodb://${program.host}:${program.port}/${program.database}?connectTimeoutMS=999999999999&socketTimeoutMs=999999999999`;



with these connection options: 

MongoClient.connect(url, {
            promiseLibrary: Promise,
            server: {
                socketOptions: {
                    connectTimeoutMs: 999999999999,
                    socketTimeoutMs: 999999999999
                }
            }
        }


and running the query with 
let cursor = db.collection(program.collection).find({
            entities: {
                media: {
                    $elemMatch: {
                        $or: [
                            { type: 'video' },
                            { type: 'photo' }
                        ]
                    }
                }
            }
        }).addCursorFlag('noCursorTimeout',true);

Still  get a timeout error after maybe a minute of waiting, can you spot anything obvious that I'm doing wrong?

Christian Kvalheim

unread,
May 23, 2016, 2:47:23 PM5/23/16
to node-mongodb-native
you are setting everything right although your timeout is not realistic try 10 minutes or 10*60*1000 milliseconds. I think your os is closing the socket early so you might want to check what the default os socket timeout is as it might be overriding whatever value you put in the field.

Christian Kvalheim

unread,
May 23, 2016, 2:47:44 PM5/23/16
to node-mongodb-native
Also maybe try the operation from the shell to compare the behavior

Max Ehrlich

unread,
May 26, 2016, 8:47:43 AM5/26/16
to node-mongodb-native
Sorry I had to spend a few days on another project. Trying the query in the terminal client was a good idea, I started the query at 7.56AM and it finished at 8:45AM but returned no results (it doesn't seem like it timed out either). When I say no results, I mean there was no printout and just running "it" to get results prints nothing. 

Christian Kvalheim

unread,
May 26, 2016, 8:54:03 AM5/26/16
to node-mongodb-native
I think the shell hid the timeout.

Max Ehrlich

unread,
May 26, 2016, 10:53:28 AM5/26/16
to node-mongodb-native
So the thinking right now is that my OS is timing out right?

--
You received this message because you are subscribed to a topic in the Google Groups "node-mongodb-native" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-mongodb-native/GUYklT_ociI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-mongodb-na...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christian Kvalheim

unread,
May 26, 2016, 11:12:32 AM5/26/16
to node-mongodb-native
very likely yeah
To unsubscribe from this group and all its topics, send an email to node-mongodb-native+unsub...@googlegroups.com.

Max Ehrlich

unread,
May 26, 2016, 2:05:52 PM5/26/16
to node-mongodb-native
https://access.redhat.com/solutions/23874

"If no packets have been sent through the connection before the idle timer expires, the firewall immediately terminates the connection and deletes it from its conn table.The idle timeout is usually set to 60 minutes."

The duration of that query was close enough to 60mins to make me wonder if that is the problem, I will try disabling this timeout and rerunning the query
Reply all
Reply to author
Forward
0 new messages