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

Commit

Permalink
fix(transactions): special case non-deterministic wc errors in txns
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Feb 4, 2019
1 parent 478d1e7 commit 5a2ae77
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,27 @@ class ClientSession extends EventEmitter {
return maybeRetryOrThrow(err);
});
}

return retryTransaction();
}
}

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 = [
'CannotSatisfyWriteConcern',
'UnknownReplWriteConcern',
'UnsatisfiableWriteConcern'
];

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

function isUnknownTransactionCommitResult(err) {
return (
['CannotSatisfyWriteConcern', 'UnknownReplWriteConcern', 'UnsatisfiableWriteConcern'].indexOf(
err.codeName
) === -1
NON_DETERMINISTIC_WRITE_CONCERN_ERRORS.indexOf(err.codeName) === -1 &&
err.code !== UNSATISFIABLE_WRITE_CONCERN_CODE &&
err.code !== UNKNOWN_REPL_WRITE_CONCERN_CODE
);
}

Expand Down

0 comments on commit 5a2ae77

Please sign in to comment.