code: 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
      )
      # these tasks should never raise, returns None on errors
      gevent.joinall(get_rtt_jobs, raise_error=False)  # block and wait tasks
      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
docs: Sorts a list of servers by http round-trip time
  
      Params:
          servers: sequence of http server urls
      Returns:
          sequence of pairs of url,rtt in seconds, sorted by rtt, excluding failed servers
          (possibly empty)