jstests/libs/override_methods/network_error_and_txn_override.js
// from the number of command retries this override counts. Throws if we should not retry.
from the number of command retries this override counts. Throws if we should not retry.
from the number of command retries this override counts . Throws if we should not retry .
function shouldRetryWithNetworkExceptionOverride(
    e, cmdName, cmdObj, startTime, numNetworkErrorRetries, logError) {
    assert(configuredForNetworkRetry());
    const kReplicaSetMonitorError =
        /^Could not find host matching read preference.*mode: "primary"/;
    if (numNetworkErrorRetries === 0) {
        logError("No retries, throwing");
        throw e;
    } else if (e.message.match(kReplicaSetMonitorError) && Date.now() - startTime < 5 * 60 * 1000) {
        logError("Failed to find primary when attempting to run command," +
                 " will retry for another 15 seconds");
        return false;
    } else if ((e.message.indexOf("writeConcernError") >= 0) && isRetryableError(e)) {
        logError("Retrying write concern error exception with retryable code");
        return false;
    } else if (!isNetworkError(e)) {
        logError("Not a network error, throwing");
        throw e;
    } else if (RetryableWritesUtil.isRetryableWriteCmdName(cmdName)) {
        if (_ServerSession.canRetryWrites(cmdObj)) {
            logError("Letting retryable writes code retry, throwing");
            throw e;
        }
    }
    logError("Retrying on ordinary network error, subtracting from retry count");
    return true;
}
function shouldRetryWithNetworkExceptionOverride ( e , cmdName , cmdObj , startTime , numNetworkErrorRetries , logError ) { assert ( configuredForNetworkRetry ( ) ) ; const kReplicaSetMonitorError = / ^Could not find host matching read preference.*mode: "primary" / ; if ( numNetworkErrorRetries === 0 ) { logError ( "No retries, throwing" ) ; throw e ; } else if ( e . message . match ( kReplicaSetMonitorError ) && Date . now ( ) - startTime < 5 * 60 * 1000 ) { logError ( "Failed to find primary when attempting to run command," + " will retry for another 15 seconds" ) ; return false ; } else if ( ( e . message . indexOf ( "writeConcernError" ) >= 0 ) && isRetryableError ( e ) ) { logError ( "Retrying write concern error exception with retryable code" ) ; return false ; } else if ( ! isNetworkError ( e ) ) { logError ( "Not a network error, throwing" ) ; throw e ; } else if ( RetryableWritesUtil . isRetryableWriteCmdName ( cmdName ) ) { if ( _ServerSession . canRetryWrites ( cmdObj ) ) { logError ( "Letting retryable writes code retry, throwing" ) ; throw e ; } } logError ( "Retrying on ordinary network error, subtracting from retry count" ) ; return true ; }
from the number of command retries this override counts.
from the number of command retries this override counts .
// ReplicaSetMonitor::getHostOrRefresh() waits up to 15 seconds to find the // primary of the replica set. It is possible for the step up attempt of another // node in the replica set to take longer than 15 seconds so we allow retrying // for up to 5 minutes. // If the command is retryable, assume the command has already gone through // or will go through the retry logic in SessionAwareClient, so propagate // the error.