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

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

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

      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?

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            mercmobily Tony Mobily
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: