Skip to content

Commit 3dad6c2

Browse files
misc cleanup
1 parent 9d2bb2c commit 3dad6c2

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/sessions.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -788,22 +788,11 @@ export class ClientSession
788788
await this.commitTransaction();
789789
committed = true;
790790
} catch (commitError) {
791+
// If CSOT is enabled, we repeatedly retry until timeoutMS expires.
792+
// If CSOT is not enabled, do we still have time remaining or have we timed out?
791793
const hasNotTimedOut =
792794
this.timeoutContext?.csotEnabled() || now() - startTime < MAX_TIMEOUT;
793795

794-
/**
795-
* will the provided backoffMS exceed the withTransaction's deadline?
796-
*/
797-
const willExceedTransactionDeadline = (backoffMS: number) => {
798-
return (
799-
(this.timeoutContext?.csotEnabled() &&
800-
backoffMS > this.timeoutContext.remainingTimeMS) ||
801-
now() + backoffMS > startTime + MAX_TIMEOUT
802-
);
803-
};
804-
805-
// If CSOT is enabled, we repeatedly retry until timeoutMS expires.
806-
// If CSOT is not enabled, do we still have time remaining or have we timed out?
807796
if (hasNotTimedOut) {
808797
if (
809798
!isMaxTimeMSExpiredError(commitError) &&
@@ -826,7 +815,12 @@ export class ClientSession
826815
const backoffMS =
827816
jitter * Math.min(BACKOFF_INITIAL_MS * 1.5 ** retry, BACKOFF_MAX_MS);
828817

829-
if (willExceedTransactionDeadline(backoffMS)) {
818+
const willExceedTransactionDeadline =
819+
(this.timeoutContext?.csotEnabled() &&
820+
backoffMS > this.timeoutContext.remainingTimeMS) ||
821+
now() + backoffMS > startTime + MAX_TIMEOUT;
822+
823+
if (willExceedTransactionDeadline) {
830824
break;
831825
}
832826

@@ -841,6 +835,7 @@ export class ClientSession
841835
}
842836
}
843837

838+
// @ts-expect-error Result is always defined if we reach here, the for-loop above convinces TS it is not.
844839
return result;
845840
} finally {
846841
this.timeoutContext = null;

0 commit comments

Comments
 (0)