Driver not reconnecting on "MongoError: Topology was destroyed"

1,722 views
Skip to first unread message

Tony Mobily

unread,
Apr 17, 2017, 8:56:19 PM4/17/17
to node-mongodb-native
Hi,

I am having a problem with my node application disconnecting from the database. I *suspect* this is due to some time of inactivity. However, I think whichever the reason, the mongodb driver *ought* to try to reconnect in such cases.
I am using the mongo db driver version 2.1.21 (from npm). Mongo is 3.4.3.

I connect to mongo in my node app with:

    // Connect to the DB
    mongodb.MongoClient.connect( mongoUrl, {
      bufferMaxEntries: 0,
      reconnectTries: -1,
    }, function( err, db ){
    //
    // ... rest of server.js


The system has a tcp keepalive of 200:

    [root@centos755208 ~]$ sudo cat  /proc/sys/net/ipv4/tcp_keepalive_time200
    [root@centos755208 ~]$ 

This is the error I am getting:

    { MongoError: Topology was destroyed
    at nextFunction (/var/www/node-apps/gigsnet-development/node_modules/mongodb-core/lib/cursor.js:540:25)
    at Cursor.next [as _next] (/var/www/node-apps/gigsnet-development/node_modules/mongodb-core/lib/cursor.js:692:3)
    at fetchDocs (/var/www/node-apps/gigsnet-development/node_modules/mongodb/lib/cursor.js:856:10)
    at toArray (/var/www/node-apps/gigsnet-development/node_modules/mongodb/lib/cursor.js:883:3)
    at Cursor.toArray (/var/www/node-apps/gigsnet-development/node_modules/mongodb/lib/cursor.js:836:44)
    at ReturnedCtor.select (/var/www/node-apps/gigsnet-development/node_modules/simpledblayer-mongo/MongoMixin.js:673:14)

The line in MongoMixin.js has:

     cursor.toArray( function( err, queryDocs ){
        if( err ) return cb( err );

What bothers me is that after this error the connection is not re-established (the app will just keep on throwing errors from downstream in the database).
So, options:

* Am I missing an option to re-establish a lost connection in the driver? As far as I can see, at *connection* time the connection is re-tried. However, once the connection has happened, if the socket is no longer available the connection is not reestablished
* Shall I look out for this error (ugh) or listen to some kind of "close" or "error" event, and just close the server if it happens? (it will re-open automatically)
* Am I missing something?

Thanks,

Merc.

Dawid Tomkalski

unread,
Aug 22, 2017, 11:34:11 PM8/22/17
to node-mongodb-native
Hi Tony,

I have the same problem. Did you find a solution?
Reply all
Reply to author
Forward
0 new messages