Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
feat(withTransaction): retry transaction commit on wtimeout
Browse files Browse the repository at this point in the history
Fixes NODE-1877
  • Loading branch information
daprahamian committed Feb 21, 2019
1 parent f036d3c commit 2bc705c
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions lib/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ class ClientSession extends EventEmitter {
}

const MAX_WITH_TRANSACTION_TIMEOUT = 120000;
const WRITE_CONCERN_FAILED_CODE = 64;
const UNSATISFIABLE_WRITE_CONCERN_CODE = 100;
const UNKNOWN_REPL_WRITE_CONCERN_CODE = 79;
const NON_DETERMINISTIC_WRITE_CONCERN_ERRORS = new Set([
Expand All @@ -284,10 +283,6 @@ function hasNotTimedOut(startTime, max) {
return Date.now() - startTime < max;
}

function isWriteConcernTimeoutError(err) {
return err.code === WRITE_CONCERN_FAILED_CODE && !!(err.errInfo && err.errInfo.wtimeout === true);
}

function isUnknownTransactionCommitResult(err) {
return (
!NON_DETERMINISTIC_WRITE_CONCERN_ERRORS.has(err.codeName) &&
Expand All @@ -299,7 +294,7 @@ function isUnknownTransactionCommitResult(err) {
function attemptTransactionCommit(session, startTime, fn, options) {
return session.commitTransaction().catch(err => {
if (err instanceof MongoError && hasNotTimedOut(startTime, MAX_WITH_TRANSACTION_TIMEOUT)) {
if (err.hasErrorLabel('UnknownTransactionCommitResult') && !isWriteConcernTimeoutError(err)) {
if (err.hasErrorLabel('UnknownTransactionCommitResult')) {
return attemptTransactionCommit(session, startTime, fn, options);
}

Expand Down

0 comments on commit 2bc705c

Please sign in to comment.