-
Type: Bug
-
Resolution: Gone away
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.1.8
-
Component/s: MongoDB 3.4
-
Environment:Linux
-
Empty show more show less
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 can't say what triggers it, but it's definitely after a while the app is running.
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,
, 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
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?
- backports
-
NODE-1439 SocketException on mongo nodes
- Closed