jstests/libs/auto_retry_transaction_in_sharding.js
/**
     * Runs 'func' and retries it only once restarting the transaction if a transient
     * error occurred.
     *
     * This behaviour only applies if the client is a mongos
     *
     * TODO SERVER-39704: Once completed, the usages of this function should be revisited to
     * determine whether it is still necessary or the retries performed by MongoS make it
     * unnecessary
     */
Runs 'func' and retries it only once restarting the transaction if a transient
error occurred.

This behaviour only applies if the client is a mongos


Runs ' func ' and retries it only once restarting the transaction if a transient error occurred . This behaviour only applies if the client is a mongos
function retryOnceOnTransientAndRestartTxnOnMongos(session, func, txnOptions) {
        if (session.getClient().isMongos()) {
            try {
                func();
            } catch (e) {
                if ((e.hasOwnProperty('errorLabels') &&
                     e.errorLabels.includes('TransientTransactionError'))) {
                    session.abortTransaction_forTesting();
                    session.startTransaction(txnOptions);
                    func();
                } else {
                    throw e;
                }
            }
        } else {
            func();
        }
    }
function retryOnceOnTransientAndRestartTxnOnMongos ( session , func , txnOptions ) { if ( session . getClient ( ) . isMongos ( ) ) { try { func ( ) ; } catch ( e ) { if ( ( e . hasOwnProperty ( 'errorLabels' ) && e . errorLabels . includes ( 'TransientTransactionError' ) ) ) { session . abortTransaction_forTesting ( ) ; session . startTransaction ( txnOptions ) ; func ( ) ; } else { throw e ; } } } else { func ( ) ; } }
Runs 'func' and retries it only once restarting the transaction if a transient
 error occurred.
Runs ' func ' and retries it only once restarting the transaction if a transient error occurred .