Skip to content

Commit

Permalink
fix: don't auto destroy read stream for Node 14
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Mar 16, 2021
1 parent f1eabf4 commit d4e297e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -6,6 +6,7 @@ logs
pids
*.pid
*.seed
*.swp
*.tmp
*.dat
*.png
Expand Down Expand Up @@ -56,4 +57,4 @@ lib/
*.d.ts

.vscode
output
output
1 change: 1 addition & 0 deletions src/cursor/abstract_cursor.ts
Expand Up @@ -730,6 +730,7 @@ export function assertUninitialized(cursor: AbstractCursor): void {
function makeCursorStream(cursor: AbstractCursor) {
const readable = new Readable({
objectMode: true,
autoDestroy: false,
highWaterMark: 1
});

Expand Down
37 changes: 37 additions & 0 deletions test/functional/cursor.test.js
Expand Up @@ -1550,6 +1550,43 @@ describe('Cursor', function () {
}
});

it('does not auto destroy streams', function (done) {
const docs = [];

for (var i = 0; i < 10; i++) {
docs.push({ a: i + 1 });
}

const configuration = this.configuration;
const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
client.connect((err, client) => {
expect(err).to.not.exist;

const db = client.db(configuration.db);
db.createCollection('does_not_autodestroy_streams', (err, collection) => {
expect(err).to.not.exist;

collection.insertMany(docs, configuration.writeConcernMax(), err => {
expect(err).to.not.exist;

const cursor = collection.find();
const stream = cursor.stream();
stream.on('close', () => {
expect.fail('extra close event must not be called');
});
stream.on('end', () => {
client.close();
done();
});
stream.on('data', doc => {
expect(doc).to.exist;
});
stream.resume();
});
});
});
});

it('should be able to stream documents', {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
Expand Down

0 comments on commit d4e297e

Please sign in to comment.