-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Native
-
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); }