Skip to content

Commit c592237

Browse files
misc cleanup to improve readability
1 parent 49c5b6f commit c592237

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/sessions.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ export class ClientSession
768768

769769
if (
770770
fnError.hasErrorLabel(MongoErrorLabel.TransientTransactionError) &&
771-
(this.timeoutContext != null || now() - startTime < MAX_TIMEOUT)
771+
(this.timeoutContext?.csotEnabled() || now() - startTime < MAX_TIMEOUT)
772772
) {
773773
continue;
774774
}
@@ -786,26 +786,26 @@ export class ClientSession
786786
await this.commitTransaction();
787787
committed = true;
788788
} catch (commitError) {
789-
/*
790-
* Note: a maxTimeMS error will have the MaxTimeMSExpired
791-
* code (50) and can be reported as a top-level error or
792-
* inside writeConcernError, ex.
793-
* { ok:0, code: 50, codeName: 'MaxTimeMSExpired' }
794-
* { ok:1, writeConcernError: { code: 50, codeName: 'MaxTimeMSExpired' } }
795-
*/
796-
if (
797-
!isMaxTimeMSExpiredError(commitError) &&
798-
commitError.hasErrorLabel(MongoErrorLabel.UnknownTransactionCommitResult) &&
799-
(this.timeoutContext != null || now() - startTime < MAX_TIMEOUT)
800-
) {
801-
continue;
802-
}
803-
804-
if (
805-
commitError.hasErrorLabel(MongoErrorLabel.TransientTransactionError) &&
806-
(this.timeoutContext != null || now() - startTime < MAX_TIMEOUT)
807-
) {
808-
break;
789+
// If CSOT is enabled, we repeatedly retry until timeoutMS expires.
790+
// If CSOT is not enabled, do we still have time remaining or have we timed out?
791+
if (this.timeoutContext?.csotEnabled() || now() - startTime < MAX_TIMEOUT) {
792+
if (
793+
!isMaxTimeMSExpiredError(commitError) &&
794+
commitError.hasErrorLabel(MongoErrorLabel.UnknownTransactionCommitResult)
795+
) {
796+
/*
797+
* Note: a maxTimeMS error will have the MaxTimeMSExpired
798+
* code (50) and can be reported as a top-level error or
799+
* inside writeConcernError, ex.
800+
* { ok:0, code: 50, codeName: 'MaxTimeMSExpired' }
801+
* { ok:1, writeConcernError: { code: 50, codeName: 'MaxTimeMSExpired' } }
802+
*/
803+
continue;
804+
}
805+
806+
if (commitError.hasErrorLabel(MongoErrorLabel.TransientTransactionError)) {
807+
break;
808+
}
809809
}
810810

811811
throw commitError;

0 commit comments

Comments
 (0)