Skip to content

Commit 61cdfc2

Browse files
hack
1 parent e90d146 commit 61cdfc2

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/operations/execute_operation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
supportsRetryableWrites
3838
} from '../utils';
3939
import { AggregateOperation } from './aggregate';
40-
import { AbstractOperation, Aspect, RetryContext } from './operation';
40+
import { AbstractOperation, Aspect } from './operation';
4141

4242
const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
4343
const MMAPv1_RETRY_WRITES_ERROR_MESSAGE =
@@ -254,17 +254,17 @@ async function executeOperationWithRetries<
254254
2 // backoff rate
255255
);
256256

257-
const retryContext =
258-
operation.retryContext ??
259-
new RetryContext(willRetry ? (timeoutContext.csotEnabled() ? Infinity : 2) : 1);
257+
let maxAttempts =
258+
(operation.maxAttempts ?? willRetry) ? (timeoutContext.csotEnabled() ? Infinity : 2) : 1;
259+
260260
for (
261261
let attempt = 0;
262-
attempt < retryContext.maxAttempts;
262+
attempt < maxAttempts;
263263
attempt++,
264-
retryContext.maxAttempts =
264+
maxAttempts =
265265
willRetry && previousOperationError?.hasErrorLabel(MongoErrorLabel.SystemOverloadedError)
266266
? 6
267-
: retryContext.maxAttempts
267+
: maxAttempts
268268
) {
269269
if (previousOperationError) {
270270
if (hasWriteAspect && previousOperationError.code === MMAPv1_RETRY_WRITES_ERROR_CODE) {

src/operations/operation.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ export interface OperationOptions extends BSONSerializeOptions {
4545
timeoutMS?: number;
4646
}
4747

48-
export class RetryContext {
49-
constructor(public maxAttempts: number) {}
50-
}
51-
5248
/**
5349
* This class acts as a parent class for any operation and is responsible for setting this.options,
5450
* as well as setting and getting a session.
@@ -70,7 +66,7 @@ export abstract class AbstractOperation<TResult = any> {
7066
/** Specifies the time an operation will run until it throws a timeout error. */
7167
timeoutMS?: number;
7268

73-
retryContext?: RetryContext;
69+
maxAttempts?: number;
7470

7571
private _session: ClientSession | undefined;
7672

src/sessions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
import type { MongoClient, MongoOptions } from './mongo_client';
2626
import { TypedEventEmitter } from './mongo_types';
2727
import { executeOperation } from './operations/execute_operation';
28-
import { RetryContext } from './operations/operation';
28+
import { RetryAttemptContext } from './operations/operation';
2929
import { RunCommandOperation } from './operations/run_command';
3030
import { ReadConcernLevel } from './read_concern';
3131
import { ReadPreference } from './read_preference';
@@ -494,14 +494,14 @@ export class ClientSession
494494
command.recoveryToken = this.transaction.recoveryToken;
495495
}
496496

497-
const retryContext = new RetryContext(5);
497+
const retryContext = new RetryAttemptContext(5);
498498

499499
const operation = new RunCommandOperation(new MongoDBNamespace('admin'), command, {
500500
session: this,
501501
readPreference: ReadPreference.primary,
502502
bypassPinningCheck: true
503503
});
504-
operation.retryContext = retryContext;
504+
operation.attempts = retryContext;
505505

506506
const timeoutContext =
507507
this.timeoutContext ??
@@ -531,7 +531,7 @@ export class ClientSession
531531
readPreference: ReadPreference.primary,
532532
bypassPinningCheck: true
533533
});
534-
op.retryContext = retryContext;
534+
op.attempts = retryContext;
535535
await executeOperation(this.client, op, timeoutContext);
536536
return;
537537
} catch (retryCommitError) {

0 commit comments

Comments
 (0)