Skip to content

Commit 30ccd86

Browse files
authored
fix: remove existing session from cloned cursors
1 parent d4e297e commit 30ccd86

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/cursor/aggregation_cursor.ts

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class AggregationCursor extends AbstractCursor {
5454

5555
clone(): AggregationCursor {
5656
const clonedOptions = mergeOptions({}, this[kOptions]);
57+
delete clonedOptions.session;
5758
return new AggregationCursor(this[kParent], this.topology, this.namespace, this[kPipeline], {
5859
...clonedOptions
5960
});

src/cursor/find_cursor.ts

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class FindCursor extends AbstractCursor {
5454

5555
clone(): FindCursor {
5656
const clonedOptions = mergeOptions({}, this[kBuiltOptions]);
57+
delete clonedOptions.session;
5758
return new FindCursor(this.topology, this.namespace, this[kFilter], {
5859
...clonedOptions
5960
});

test/functional/cursor.test.js

+62
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,68 @@ describe('Cursor', function () {
17301730
}
17311731
});
17321732

1733+
it('removes session wheen cloning a find cursor', function (done) {
1734+
const configuration = this.configuration;
1735+
const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
1736+
client.connect((err, client) => {
1737+
expect(err).to.not.exist;
1738+
1739+
const db = client.db(configuration.db);
1740+
db.createCollection('clone_find_cursor_session', (err, collection) => {
1741+
expect(err).to.not.exist;
1742+
1743+
collection.insertOne({ a: 1 }, configuration.writeConcernMax(), err => {
1744+
expect(err).to.not.exist;
1745+
1746+
const cursor = collection.find();
1747+
const clonedCursor = cursor.clone();
1748+
cursor.toArray(err => {
1749+
expect(err).to.not.exist;
1750+
clonedCursor.toArray(err => {
1751+
expect(err).to.not.exist;
1752+
client.close();
1753+
done();
1754+
});
1755+
});
1756+
});
1757+
});
1758+
});
1759+
});
1760+
1761+
it('removes session wheen cloning an aggregation cursor', {
1762+
metadata: {
1763+
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
1764+
},
1765+
1766+
test: function (done) {
1767+
const configuration = this.configuration;
1768+
const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
1769+
client.connect((err, client) => {
1770+
expect(err).to.not.exist;
1771+
1772+
const db = client.db(configuration.db);
1773+
db.createCollection('clone_aggregation_cursor_session', (err, collection) => {
1774+
expect(err).to.not.exist;
1775+
1776+
collection.insertOne({ a: 1 }, configuration.writeConcernMax(), err => {
1777+
expect(err).to.not.exist;
1778+
1779+
const cursor = collection.aggregate([{ $match: { a: 1 } }]);
1780+
const clonedCursor = cursor.clone();
1781+
cursor.toArray(err => {
1782+
expect(err).to.not.exist;
1783+
clonedCursor.toArray(err => {
1784+
expect(err).to.not.exist;
1785+
client.close();
1786+
done();
1787+
});
1788+
});
1789+
});
1790+
});
1791+
});
1792+
}
1793+
});
1794+
17331795
it('destroying a stream stops it', {
17341796
// Add a tag that our runner can trigger on
17351797
// in this case we are setting that node needs to be higher than 0.10.X to run

0 commit comments

Comments
 (0)