'Re-create a mal-functioning connection.
:param bad_conn: The bad connection
:param req: The request we want to send using the new connection
:param conn_factory: The factory function for new connection creation.'

def replace_connection(self, bad_conn, req, conn_factory):

    bad_conn.close()
    host = req.get_host()
    with self._lock:
        self.remove_connection(bad_conn, host, reason='replace    connection')
        new_conn = conn_factory(req)
        conns = self._hostmap.setdefault(host, [])
        conns.append(new_conn)
        self._used_cons.append(new_conn)
        args = (bad_conn, new_conn)
        debug(('Replaced    broken    %s    with    the    new    %s' % args))
        return new_conn
