Skip to content

Commit d4e297e

Browse files
authored
fix: don't auto destroy read stream for Node 14
1 parent f1eabf4 commit d4e297e

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ logs
66
pids
77
*.pid
88
*.seed
9+
*.swp
910
*.tmp
1011
*.dat
1112
*.png
@@ -56,4 +57,4 @@ lib/
5657
*.d.ts
5758

5859
.vscode
59-
output
60+
output

src/cursor/abstract_cursor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ export function assertUninitialized(cursor: AbstractCursor): void {
730730
function makeCursorStream(cursor: AbstractCursor) {
731731
const readable = new Readable({
732732
objectMode: true,
733+
autoDestroy: false,
733734
highWaterMark: 1
734735
});
735736

test/functional/cursor.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,43 @@ describe('Cursor', function () {
15501550
}
15511551
});
15521552

1553+
it('does not auto destroy streams', function (done) {
1554+
const docs = [];
1555+
1556+
for (var i = 0; i < 10; i++) {
1557+
docs.push({ a: i + 1 });
1558+
}
1559+
1560+
const configuration = this.configuration;
1561+
const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
1562+
client.connect((err, client) => {
1563+
expect(err).to.not.exist;
1564+
1565+
const db = client.db(configuration.db);
1566+
db.createCollection('does_not_autodestroy_streams', (err, collection) => {
1567+
expect(err).to.not.exist;
1568+
1569+
collection.insertMany(docs, configuration.writeConcernMax(), err => {
1570+
expect(err).to.not.exist;
1571+
1572+
const cursor = collection.find();
1573+
const stream = cursor.stream();
1574+
stream.on('close', () => {
1575+
expect.fail('extra close event must not be called');
1576+
});
1577+
stream.on('end', () => {
1578+
client.close();
1579+
done();
1580+
});
1581+
stream.on('data', doc => {
1582+
expect(doc).to.exist;
1583+
});
1584+
stream.resume();
1585+
});
1586+
});
1587+
});
1588+
});
1589+
15531590
it('should be able to stream documents', {
15541591
// Add a tag that our runner can trigger on
15551592
// in this case we are setting that node needs to be higher than 0.10.X to run

0 commit comments

Comments
 (0)