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

useUnifiedTopology - replicaset

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 3.3.5
    • Affects Version/s: 3.3.4
    • Component/s: None
    • Labels:

      I did some tests about connection errors with different options and I got different error each time.

      // This code logs errors and read from collection in infinite loop
      const dbServiceProvider = 'test';
      const connString = 'mongodb://xxx:27017,xxx:27017,xxx:27017';
      const options = {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        poolSize: 2,
        ssl: true,
        authSource: 'admin',
        replicaSet: 'xxx',
        auth: { user: 'xxx', password: 'xxx' },
      };
      async function wait(ms) {
        return new Promise((resolve) => {
          setTimeout(resolve, ms);
        });
      }
      async function connect() {
        const client = await MongoClient.connect(connString, options);
        client.on('error', (error) => {
          if (error) {
            logger.fatal(error, `Event close client: ${error.message}`);
            process.exit(1);
          }
        });
        client.on('close', (info) => {
          logger.warn('CLOSING!', info);
        });
        client.on('serverClosed', (info) => {
          logger.warn('serverClosed!', info);
        });
      
        // reconnectFailed event works only with useUnifiedTopology = false
        client.topology.on('reconnectFailed', (error) => {
          logger.fatal(error, `reconnectFailed: ${error.message}`);
          process.exit(1);
        });
        return client.db(dbServiceProvider);
      }
      
      async function test() {
        const dbClient = await connect();
        while (true) {
          await wait(2000);
          try {
            // const loopResult = await dbManager.findOneById(dbServiceProvider, collection, result._id);
            const result = await dbClient.collection(collection).find({}).limit(1).toArray();
            // logger.info(loopResult, 'data loaded');
            console.log('data loaded');
          } catch (e) {
            logger.error(e, 'error');
          }
        }
      }
      
      test();
      

      3.3.4 - useUnifiedTopology=true replica set
      I run the code and I tried to stop and restart internet connection (i stopped the internet connection for at least 30sec=> default reconnection timeout).
      Sometimes the code is stuck on await dbManager.findOneById: No errors logged, simply the promise will never be resolved. Sometimes instead, randomly, it works correctly, the promise will return correct value.

       If I repeat the same test with useUnifiedTopology=false  the code doesn't get stuck (the dbClient.collection(collection).find promise throws an exception)

       

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            ballabio@intre.it Carlo Ballabio
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: