def sort_servers_closest(servers: Sequence[str]) -> Sequence[Tuple[str, float]]:
    if not {urlparse(url).scheme for url in servers}.issubset({'http', 'https'}):
        raise TransportError('Invalid server urls')
    get_rtt_jobs = set(
        gevent.spawn(lambda url: (url, get_http_rtt(url)), server_url)
        for server_url
        in servers
    )
    gevent.joinall(get_rtt_jobs, raise_error=False)
    sorted_servers: List[Tuple[str, float]] = sorted(
        (job.value for job in get_rtt_jobs if job.value[1] is not None),
        key=itemgetter(1),
    )
    log.debug('Matrix homeserver RTT times', rtt_times=sorted_servers)
    return sorted_servers