• Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.1.8
    • Affects Version/s: None
    • Component/s: None

      The MongoDb driver, sometimes, does not reconnect automatically. My application simply just stop working because the driver didn't reconnected. If I restart the application it works properly.

      I've made a simples script to test it.

      const mongodb = require('mongodb');
      const MongoClient = mongodb.MongoClient;
      
      function randomIndex() {
        return Math.ceil(Math.random() * 2100);
      }
      
      MongoClient.connect('mongodb://localhost/somedb').then(db => {
        let collection = db.collection('somecollection');
        db.on('close', err => console.log('close', err));
        db.on('reconnect', () => console.trace('reconnect'));
      
        setInterval(() => {
          collection.find({
            index: randomIndex()
          }).limit(1).next()
            .then(console.log)
            .catch(console.log);
        }, 1000);
      });
      

      Steps to reproduce the error:

      • Start mongodb
      • Start script
      • Stop mongodb
      • Restart mongodb
      • Stop mongodb
      • Restart mongodb

      After restarting it for the second time, my application running on node does not reconnect to mongo.

      I think I have found the solution for this and made a pull request https://github.com/christkv/mongodb-core/pull/78.

      I would like you to check if my solution is valid.

      Thanks

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            luiz290788 Luiz Guilherme Pereira
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: