code: def _finish_transaction_with_retry(self, command_name, explict_retry):
          
          # This can be refactored with MongoClient._retry_with_session.
          try:
              return self._finish_transaction(command_name, explict_retry)
          except ServerSelectionTimeoutError:
              raise
          except ConnectionFailure as exc:
              try:
                  return self._finish_transaction(command_name, True)
              except ServerSelectionTimeoutError:
                  # Raise the original error so the application can infer that
                  # an attempt was made.
                  raise exc
          except OperationFailure as exc:
              if exc.code not in _RETRYABLE_ERROR_CODES:
                  raise
              try:
                  return self._finish_transaction(command_name, True)
              except ServerSelectionTimeoutError:
                  # Raise the original error so the application can infer that
                  # an attempt was made.
                  raise exc
docs: Run commit or abort with one retry after any retryable error.
  
          :Parameters:
            - `command_name`: Either "commitTransaction" or "abortTransaction".
            - `explict_retry`: True when this is an explict commit retry attempt,
              ie the application called session.commit_transaction() twice.