jstests/libs/override_methods/network_error_and_txn_override.js
// for failures with acceptable error codes, unless shouldOverrideAcceptableError is false.
for failures with acceptable error codes, unless shouldOverrideAcceptableError is false.
for failures with acceptable error codes unless shouldOverrideAcceptableError is false .
function shouldRetryWithNetworkErrorOverride(
    res, cmdName, logError, shouldOverrideAcceptableError = true) {
    assert(configuredForNetworkRetry());
    if (RetryableWritesUtil.isRetryableWriteCmdName(cmdName)) {
        if ((cmdName === "findandmodify" || cmdName === "findAndModify") &&
            isRetryableExecutorCodeAndMessage(res.code, res.errmsg)) {
            logError("Retrying because of executor interruption");
            return kContinue;
        }
        return res;
    }
    if (cmdName === "commitTransaction" && hasWriteConcernError(res)) {
        logError("Retrying write concern error response for commitTransaction");
        return kContinue;
    }
    if (cmdName === "explain") {
        if (res.hasOwnProperty("executionStats") && !res.executionStats.executionSuccess &&
            (RetryableWritesUtil.isRetryableCode(res.executionStats.errorCode) ||
             isRetryableExecutorCodeAndMessage(res.executionStats.errorCode,
                                               res.executionStats.errorMessage))) {
            logError("Forcing retry of interrupted explain");
            return kContinue;
        }
        if (!res.ok && res.errmsg.indexOf("child command cannot run on this node") >= 0) {
            logError("Forcing retry of explain likely interrupted by transition to secondary");
            return kContinue;
        }
    }
    if (!res.ok) {
        if (RetryableWritesUtil.isRetryableCode(res.code)) {
            logError("Retrying failed response with retryable code");
            return kContinue;
        }
        if (isRetryableExecutorCodeAndMessage(res.code, res.errmsg)) {
            logError("Retrying because of executor interruption");
            return kContinue;
        }
         TODO SERVER-30949: Remove this check once those two commands retry on retryable
         errors automatically.
        if ((cmdName === "listCollections" || cmdName === "listIndexes") &&
            res.code === ErrorCodes.OperationFailed && res.hasOwnProperty("errmsg") &&
            res.errmsg.indexOf("failed to read command response from shard") >= 0) {
            logError("Retrying failed mongos cursor command");
            return kContinue;
        }
         Some sharding commands return raw responses from all contacted shards and there won't
         be a top level code if shards returned more than one error code, in which case retry
         if any error is retryable.
        if (res.hasOwnProperty("raw") && !res.hasOwnProperty("code") &&
            rawResponseHasRetryableError(res.raw, cmdName, logError)) {
            logError("Retrying because of retryable code in raw response");
            return kContinue;
        }
         Check for the retryable error codes from an interrupted shardCollection.
        if (cmdName === "shardCollection" && isRetryableShardCollectionResponse(res)) {
            logError("Retrying interrupted shardCollection");
            return kContinue;
        }
         Check for the retryable error codes from an interrupted moveChunk.
        if (cmdName === "moveChunk" && isRetryableMoveChunkResponse(res)) {
            logError("Retrying interrupted moveChunk");
            return kContinue;
        }
         In a sharded cluster, drop may bury the original error code in the error message if
         interrupted.
        if (cmdName === "drop" && RetryableWritesUtil.errmsgContainsRetryableCodeName(res.errmsg)) {
            logError("Retrying interrupted drop");
            return kContinue;
        }
        if (!shouldOverrideAcceptableError || !isAcceptableRetryFailedResponse(cmdName, res)) {
             Pass up unretryable errors.
            return res;
        }
         Swallow safe errors that may come from a retry since the command may have completed
         before the connection was closed.
        logError("Overriding safe failed response for");
        res.ok = 1;
         Fall through to retry on write concern errors if needed.
    }
     Do not retry on a write concern error at this point if there is an actual error.
     TransientTransactionErrors would already have been retried at an earlier point.
    if (hasWriteConcernError(res) && !hasError(res)) {
        if (RetryableWritesUtil.isRetryableCode(res.writeConcernError.code)) {
            logError("Retrying write concern error response with retryable code");
            return kContinue;
        }
    }
    return res;
}
function shouldRetryWithNetworkErrorOverride ( res , cmdName , logError , shouldOverrideAcceptableError = true ) { assert ( configuredForNetworkRetry ( ) ) ; if ( RetryableWritesUtil . isRetryableWriteCmdName ( cmdName ) ) { if ( ( cmdName === "findandmodify" || cmdName === "findAndModify" ) && isRetryableExecutorCodeAndMessage ( res . code , res . errmsg ) ) { logError ( "Retrying because of executor interruption" ) ; return kContinue ; } return res ; } if ( cmdName === "commitTransaction" && hasWriteConcernError ( res ) ) { logError ( "Retrying write concern error response for commitTransaction" ) ; return kContinue ; } if ( cmdName === "explain" ) { if ( res . hasOwnProperty ( "executionStats" ) && ! res . executionStats . executionSuccess && ( RetryableWritesUtil . isRetryableCode ( res . executionStats . errorCode ) || isRetryableExecutorCodeAndMessage ( res . executionStats . errorCode , res . executionStats . errorMessage ) ) ) { logError ( "Forcing retry of interrupted explain" ) ; return kContinue ; } if ( ! res . ok && res . errmsg . indexOf ( "child command cannot run on this node" ) >= 0 ) { logError ( "Forcing retry of explain likely interrupted by transition to secondary" ) ; return kContinue ; } } if ( ! res . ok ) { if ( RetryableWritesUtil . isRetryableCode ( res . code ) ) { logError ( "Retrying failed response with retryable code" ) ; return kContinue ; } if ( isRetryableExecutorCodeAndMessage ( res . code , res . errmsg ) ) { logError ( "Retrying because of executor interruption" ) ; return kContinue ; } if ( ( cmdName === "listCollections" || cmdName === "listIndexes" ) && res . code === ErrorCodes . OperationFailed && res . hasOwnProperty ( "errmsg" ) && res . errmsg . indexOf ( "failed to read command response from shard" ) >= 0 ) { logError ( "Retrying failed mongos cursor command" ) ; return kContinue ; } if ( res . hasOwnProperty ( "raw" ) && ! res . hasOwnProperty ( "code" ) && rawResponseHasRetryableError ( res . raw , cmdName , logError ) ) { logError ( "Retrying because of retryable code in raw response" ) ; return kContinue ; } if ( cmdName === "shardCollection" && isRetryableShardCollectionResponse ( res ) ) { logError ( "Retrying interrupted shardCollection" ) ; return kContinue ; } if ( cmdName === "moveChunk" && isRetryableMoveChunkResponse ( res ) ) { logError ( "Retrying interrupted moveChunk" ) ; return kContinue ; } if ( cmdName === "drop" && RetryableWritesUtil . errmsgContainsRetryableCodeName ( res . errmsg ) ) { logError ( "Retrying interrupted drop" ) ; return kContinue ; } if ( ! shouldOverrideAcceptableError || ! isAcceptableRetryFailedResponse ( cmdName , res ) ) { return res ; } logError ( "Overriding safe failed response for" ) ; res . ok = 1 ; } if ( hasWriteConcernError ( res ) && ! hasError ( res ) ) { if ( RetryableWritesUtil . isRetryableCode ( res . writeConcernError . code ) ) { logError ( "Retrying write concern error response with retryable code" ) ; return kContinue ; } } return res ; }
for failures with acceptable error codes, unless shouldOverrideAcceptableError is false.
for failures with acceptable error codes unless shouldOverrideAcceptableError is false .
// findAndModify can fail during the find stage and return an executor error. // Don't interfere with retryable writes. // commitTransaction should be retried on any write concern error. // If an explain is interrupted by a stepdown, and it returns before its connection is // closed, it will return incomplete results. To prevent failing the test, force retries // of interrupted explains. // An explain command can fail if its child command cannot be run on the current server. // This can be hit if a primary only or not explicitly slaveOk command is accepted by a // primary node that then steps down and returns before having its connection closed. // Don't decrement retries, because the command returned before the connection was // closed, so a subsequent attempt will receive a network error (or NotWritablePrimary // error) and need to retry. // listCollections and listIndexes called through mongos may return OperationFailed if // the request to establish a cursor on the targeted shard fails with a network error. // // TODO SERVER-30949: Remove this check once those two commands retry on retryable // errors automatically. // Some sharding commands return raw responses from all contacted shards and there won't // be a top level code if shards returned more than one error code, in which case retry // if any error is retryable. // Check for the retryable error codes from an interrupted shardCollection. // Check for the retryable error codes from an interrupted moveChunk. // In a sharded cluster, drop may bury the original error code in the error message if // interrupted. // Pass up unretryable errors. // Swallow safe errors that may come from a retry since the command may have completed // before the connection was closed. // Fall through to retry on write concern errors if needed. // Do not retry on a write concern error at this point if there is an actual error. // TransientTransactionErrors would already have been retried at an earlier point.