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

ChangeStream does not recover on resumable errors in stream mode

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.4
    • Affects Version/s: None
    • Component/s: Native
    • Labels:
      None

      The ChangeStream class in native has a path for recovering from resumable errors when used directly as a cursor. When used as a stream (which is most likely the general use case), errors are emitted as events and completely bypass our resume logic.

      The following code sample should be run against a three node replicaset. When the code is running, the tester should manually run rs.stepDown() on the active primary to witness the bug.

      const mongodb = require('mongodb');
      const GITHUB_ISSUE = `gh6741`;
      const connectionString = `mongodb://localhost:31000/${GITHUB_ISSUE}`;
      
      run().then(() => console.log('done')).catch(error => console.error(error.stack));
      
      async function run() {
        const client = await mongodb.connect(connectionString, { useNewUrlParser: true, replicaSet: 'replset' });
        await client.db().createCollection('foo');
      
        let changeStream = client.db().collection('foo').watch();
        changeStream.on('change', change => console.log(change));
        setInterval(() => {
          client.db().collection('foo').insertOne({ a: Math.floor(Math.random() % 1000) });
        }, 1000);
      }
      

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            matt.broadstone@mongodb.com Matt Broadstone
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: