Skip to content

Commit 112c2fa

Browse files
Pavel's comments
1 parent 46686b8 commit 112c2fa

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/sessions.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,10 @@ export class ClientSession
792792
// timeoutContext to each async API, which know how to cancel themselves (i.e., the next retry will
793793
// abort the withTransaction call).
794794
// If CSOT is not enabled, do we still have time remaining or have we timed out?
795-
const hasNotTimedOut =
796-
this.timeoutContext?.csotEnabled() || now() - startTime < MAX_TIMEOUT;
795+
const hasTimedOut =
796+
!this.timeoutContext?.csotEnabled() && now() - startTime >= MAX_TIMEOUT;
797797

798-
if (hasNotTimedOut) {
798+
if (!hasTimedOut) {
799799
if (
800800
!isMaxTimeMSExpiredError(commitError) &&
801801
commitError.hasErrorLabel(MongoErrorLabel.UnknownTransactionCommitResult)
@@ -813,9 +813,10 @@ export class ClientSession
813813
if (commitError.hasErrorLabel(MongoErrorLabel.TransientTransactionError)) {
814814
const BACKOFF_INITIAL_MS = 5;
815815
const BACKOFF_MAX_MS = 500;
816+
const BACKOFF_GROWTH = 1.5;
816817
const jitter = Math.random();
817818
const backoffMS =
818-
jitter * Math.min(BACKOFF_INITIAL_MS * 1.5 ** retry, BACKOFF_MAX_MS);
819+
jitter * Math.min(BACKOFF_INITIAL_MS * BACKOFF_GROWTH ** retry, BACKOFF_MAX_MS);
819820

820821
const willExceedTransactionDeadline =
821822
(this.timeoutContext?.csotEnabled() &&

0 commit comments

Comments
 (0)