Skip to content

Commit

Permalink
fix: make sure close does not end early but killed does
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Apr 30, 2024
1 parent c2a18e4 commit ff12d3d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/cursor/abstract_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { Readable, Transform } from 'stream';

import { type BSONSerializeOptions, type Document, Long, pluckBSONSerializeOptions } from '../bson';
import {
type AnyError,
MongoAPIError,
MongoCursorExhaustedError,
MongoCursorInUseError,
MongoInvalidArgumentError,
MongoNetworkError,
MongoRuntimeError,
MongoTailableCursorError
} from '../error';
Expand Down Expand Up @@ -300,7 +298,11 @@ export abstract class AbstractCursor<

try {
while (true) {
if (this.closed) {
if (this.killed) {
return;
}

if (this.closed && this[kDocuments].length === 0) {
return;
}

Expand Down
1 change: 0 additions & 1 deletion test/integration/change-streams/change_stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { PassThrough } from 'stream';
import { setTimeout } from 'timers';

import {
AbstractCursor,
type ChangeStream,
type ChangeStreamOptions,
type Collection,
Expand Down
2 changes: 0 additions & 2 deletions test/integration/change-streams/change_streams.prose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as sinon from 'sinon';
import { setTimeout } from 'timers';

import {
AbstractCursor,
type ChangeStream,
type CommandFailedEvent,
type CommandStartedEvent,
Expand All @@ -18,7 +17,6 @@ import {
Timestamp
} from '../../mongodb';
import * as mock from '../../tools/mongodb-mock/index';
import { getSymbolFrom } from '../../tools/utils';
import { setupDatabase } from '../shared';

/**
Expand Down
2 changes: 1 addition & 1 deletion test/integration/crud/misc_cursors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ describe('Cursor', function () {
const rejectedEarlyBecauseClientClosed = cursor.next().catch(error => error);

await client.close();
expect(cursor).to.have.property('killed', true);
expect(cursor).to.have.property('closed', true);

const error = await rejectedEarlyBecauseClientClosed;
expect(error).to.be.instanceOf(MongoExpiredSessionError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe('Cursor Async Iterator Tests', function () {
await cursor.close();

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

expect(count).to.equal(0);
Expand Down

0 comments on commit ff12d3d

Please sign in to comment.