def establish_socket_connection(self, address_list):
    'Given a list of database node addresses, establish the socket\n           connection to the database server. Return a connected socket object.\n        '
    addrinfo = address_list.peek()
    raw_socket = None
    last_exception = None
    while addrinfo:
        (family, socktype, proto, canonname, sockaddr) = addrinfo
        last_exception = None
        host = sockaddr[0]
        port = sockaddr[1]
        self._logger.info('Establishing connection to host "{0}" on port {1}'.format(host, port))
        try:
            raw_socket = self.create_socket(family)
            raw_socket.connect(sockaddr)
            break
        except Exception as e:
            self._logger.info('Failed to connect to host "{0}" on port {1}: {2}'.format(host, port, e))
            last_exception = e
            address_list.pop()
            addrinfo = address_list.peek()
            raw_socket.close()
    if ((raw_socket is None) or last_exception):
        err_msg = 'Failed to establish a connection to the primary server or any backup address.'
        self._logger.error(err_msg)
        raise errors.ConnectionError(err_msg)
    return raw_socket
Given a list of database node addresses, establish the socket
connection to the database server. Return a connected socket object.
def establish_socket_connection(self, address_list):
    'Given a list of database node addresses, establish the socket\n           connection to the database server. Return a connected socket object.\n        '
    addrinfo = address_list.peek()
    raw_socket = None
    last_exception = None
    while addrinfo:
        (family, socktype, proto, canonname, sockaddr) = addrinfo
        last_exception = None
        host = sockaddr[0]
        port = sockaddr[1]
        self._logger.info('Establishing connection to host "{0}" on port {1}'.format(host, port))
        try:
            raw_socket = self.create_socket(family)
            raw_socket.connect(sockaddr)
            break
        except Exception as e:
            self._logger.info('Failed to connect to host "{0}" on port {1}: {2}'.format(host, port, e))
            last_exception = e
            address_list.pop()
            addrinfo = address_list.peek()
            raw_socket.close()
    if ((raw_socket is None) or last_exception):
        err_msg = 'Failed to establish a connection to the primary server or any backup address.'
        self._logger.error(err_msg)
        raise errors.ConnectionError(err_msg)
    return raw_socket