Skip to content

Commit 507af55

Browse files
committed
timeoutContext refresh fix
1 parent 9fc4c4e commit 507af55

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/cursor/abstract_cursor.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,20 @@ export abstract class AbstractCursor<
444444
throw new MongoCursorExhaustedError();
445445
}
446446

447-
try {
448-
do {
449-
const doc = this.documents?.shift(this.cursorOptions);
450-
if (doc != null) {
451-
if (this.transform != null) return await this.transformDocument(doc);
452-
return doc;
453-
}
454-
await this.fetchBatch();
455-
} while (!this.isDead || (this.documents?.length ?? 0) !== 0);
447+
if (this.cursorOptions.timeoutMode === CursorTimeoutMode.ITERATION) {
448+
this.timeoutContext?.refresh();
449+
}
456450

457-
return null;
458-
} finally {
459-
if (this.cursorOptions.timeoutMode === CursorTimeoutMode.ITERATION) {
460-
this.timeoutContext?.refresh();
451+
do {
452+
const doc = this.documents?.shift(this.cursorOptions);
453+
if (doc != null) {
454+
if (this.transform != null) return await this.transformDocument(doc);
455+
return doc;
461456
}
462-
}
457+
await this.fetchBatch();
458+
} while (!this.isDead || (this.documents?.length ?? 0) !== 0);
459+
460+
return null;
463461
}
464462

465463
/**

src/timeout.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export class Timeout extends Promise<never> {
8787
clear(): void {
8888
clearTimeout(this.id);
8989
this.id = undefined;
90+
this.timedOut = false;
9091
this.cleared = true;
9192
}
9293

@@ -209,7 +210,6 @@ export class CSOTTimeoutContext extends TimeoutContext {
209210
}
210211

211212
get maxTimeMS(): number {
212-
console.log(this.remainingTimeMS, this.minRoundTripTime);
213213
return this.remainingTimeMS - this.minRoundTripTime;
214214
}
215215

@@ -282,12 +282,14 @@ export class CSOTTimeoutContext extends TimeoutContext {
282282
this.start = Math.trunc(performance.now());
283283
this.minRoundTripTime = 0;
284284
this._serverSelectionTimeout?.clear();
285-
this._connectionCheckoutTimeout?.clear();
285+
this._serverSelectionTimeout = undefined;
286+
this._connectionCheckoutTimeout = undefined;
286287
}
287288

288289
clear(): void {
289290
this._serverSelectionTimeout?.clear();
290-
this._connectionCheckoutTimeout?.clear();
291+
this._serverSelectionTimeout = undefined;
292+
this._connectionCheckoutTimeout = undefined;
291293
}
292294
}
293295

0 commit comments

Comments
 (0)