Uploaded image for project: 'Node Driver'
  1. Node Driver
  2. NODE-982

Won't reconnect after "MongoError: Topology was destroyed"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Gone away
    • Affects Version/s: 2.1.8
    • Fix Version/s: None
    • Component/s: MongoDB 3.4
    • Labels:
    • Environment:
      Linux

      Description

      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,

      { 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

      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?

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: