0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 00:17:37 +01:00
mongodb/jstests/libs/killed_session_util.js
Joseph Prince b0ff046f05 SERVER-92929 Allow retry_on_killed_session to retry if the originalError was interrupted (#25416)
GitOrigin-RevId: 8f843053759c52d05b108fce1bc1953424e3bf7c
2024-08-01 16:44:13 +00:00

31 lines
1.1 KiB
JavaScript

/**
* Utilities for testing when sessions are killed.
*/
export var KilledSessionUtil = (function() {
// Returns if the code is one that could come from a session being killed.
function isKilledSessionCode(code) {
return code === ErrorCodes.Interrupted || code === ErrorCodes.CursorKilled ||
code === ErrorCodes.CursorNotFound || code === ErrorCodes.QueryPlanKilled;
}
function hasKilledSessionError(errOrRes) {
let hasOriginalErrorKilledSessionCode =
errOrRes.code == ErrorCodes.TransactionParticipantFailedUnyield
? isKilledSessionCode(errOrRes.originalError.code)
: false;
return hasOriginalErrorKilledSessionCode || isKilledSessionCode(errOrRes.code) ||
(Array.isArray(errOrRes.writeErrors) &&
errOrRes.writeErrors.every(writeError => isKilledSessionCode(writeError.code)));
}
function hasKilledSessionWCError(res) {
return res.writeConcernError && isKilledSessionCode(res.writeConcernError.code);
}
return {
isKilledSessionCode,
hasKilledSessionError,
hasKilledSessionWCError,
};
})();