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

Client reconnection does not reconnect cached db

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.0.4
    • Component/s: None
    • Environment:
      os : macOS 10.13.3
      node : 9.8.0
      mongo-server : 3.4.14
    • Not Needed

      When closing and reopening a connection where a db was cached, the cached db is not notified of the reconnection (db.serverConfig.isDestroyed() === true).

      Code to reproduce:
      const MongoClient = require('mongodb').MongoClient;
      
      async function fun() {
        // Connect
        const client = new MongoClient('mongodb://localhost:27017');
        await client.connect();
        // Put db in cache
        let col = client.db('foo').collection('bar');
        await col.insert({ foo: 'bar' });
        // Disconnect
        await client.close();
        // Reconnect
        await client.connect();
        try {
          console.log('Destroyed ===', client.db('foo').serverConfig.isDestroyed()); // => true
          col = client.db('foo').collection('bar');
          // will fail
          await col.insert({ foo: 'bar' });
        } finally {
          await client.close();
        }
      }
      
      fun().then(console.log).catch(console.error);
      
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            Banst Bastien Arata
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: