Skip to content

Commit ff12d3d

Browse files
committed
fix: make sure close does not end early but killed does
1 parent c2a18e4 commit ff12d3d

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

src/cursor/abstract_cursor.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import { Readable, Transform } from 'stream';
22

33
import { type BSONSerializeOptions, type Document, Long, pluckBSONSerializeOptions } from '../bson';
44
import {
5-
type AnyError,
65
MongoAPIError,
76
MongoCursorExhaustedError,
87
MongoCursorInUseError,
98
MongoInvalidArgumentError,
10-
MongoNetworkError,
119
MongoRuntimeError,
1210
MongoTailableCursorError
1311
} from '../error';
@@ -300,7 +298,11 @@ export abstract class AbstractCursor<
300298

301299
try {
302300
while (true) {
303-
if (this.closed) {
301+
if (this.killed) {
302+
return;
303+
}
304+
305+
if (this.closed && this[kDocuments].length === 0) {
304306
return;
305307
}
306308

test/integration/change-streams/change_stream.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { PassThrough } from 'stream';
77
import { setTimeout } from 'timers';
88

99
import {
10-
AbstractCursor,
1110
type ChangeStream,
1211
type ChangeStreamOptions,
1312
type Collection,

test/integration/change-streams/change_streams.prose.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as sinon from 'sinon';
44
import { setTimeout } from 'timers';
55

66
import {
7-
AbstractCursor,
87
type ChangeStream,
98
type CommandFailedEvent,
109
type CommandStartedEvent,
@@ -18,7 +17,6 @@ import {
1817
Timestamp
1918
} from '../../mongodb';
2019
import * as mock from '../../tools/mongodb-mock/index';
21-
import { getSymbolFrom } from '../../tools/utils';
2220
import { setupDatabase } from '../shared';
2321

2422
/**

test/integration/crud/misc_cursors.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ describe('Cursor', function () {
18701870
const rejectedEarlyBecauseClientClosed = cursor.next().catch(error => error);
18711871

18721872
await client.close();
1873-
expect(cursor).to.have.property('killed', true);
1873+
expect(cursor).to.have.property('closed', true);
18741874

18751875
const error = await rejectedEarlyBecauseClientClosed;
18761876
expect(error).to.be.instanceOf(MongoExpiredSessionError);

test/integration/node-specific/cursor_async_iterator.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ describe('Cursor Async Iterator Tests', function () {
7777
await cursor.close();
7878

7979
let count = 0;
80+
// eslint-disable-next-line no-unused-vars
8081
for await (const _ of cursor) count++;
8182

8283
expect(count).to.equal(0);

0 commit comments

Comments
 (0)