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

Commit 5a2ae77

Browse files
committed
fix(transactions): special case non-deterministic wc errors in txns
1 parent 478d1e7 commit 5a2ae77

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/sessions.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -328,20 +328,27 @@ class ClientSession extends EventEmitter {
328328
return maybeRetryOrThrow(err);
329329
});
330330
}
331-
332-
return retryTransaction();
333331
}
334332
}
335333

334+
const WRITE_CONCERN_FAILED_CODE = 64;
335+
const UNSATISFIABLE_WRITE_CONCERN_CODE = 100;
336+
const UNKNOWN_REPL_WRITE_CONCERN_CODE = 79;
337+
const NON_DETERMINISTIC_WRITE_CONCERN_ERRORS = [
338+
'CannotSatisfyWriteConcern',
339+
'UnknownReplWriteConcern',
340+
'UnsatisfiableWriteConcern'
341+
];
342+
336343
function isWriteConcernTimeoutError(err) {
337-
return err.code === 64 && !!(err.errInfo && err.errInfo.wtimeout === true);
344+
return err.code === WRITE_CONCERN_FAILED_CODE && !!(err.errInfo && err.errInfo.wtimeout === true);
338345
}
339346

340347
function isUnknownTransactionCommitResult(err) {
341348
return (
342-
['CannotSatisfyWriteConcern', 'UnknownReplWriteConcern', 'UnsatisfiableWriteConcern'].indexOf(
343-
err.codeName
344-
) === -1
349+
NON_DETERMINISTIC_WRITE_CONCERN_ERRORS.indexOf(err.codeName) === -1 &&
350+
err.code !== UNSATISFIABLE_WRITE_CONCERN_CODE &&
351+
err.code !== UNKNOWN_REPL_WRITE_CONCERN_CODE
345352
);
346353
}
347354

0 commit comments

Comments
 (0)