From b6c05e0865713fb5fcce558ca31c683b08db82c4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 28 Oct 2023 15:09:12 -0700 Subject: [PATCH] build/sage_bootstrap/download/mirror_list.py: Use socket timeout of 1s unconditionally, stop when 5 good mirrors are found --- build/sage_bootstrap/download/mirror_list.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build/sage_bootstrap/download/mirror_list.py b/build/sage_bootstrap/download/mirror_list.py index a8baa66da2d..4cab19f5d64 100644 --- a/build/sage_bootstrap/download/mirror_list.py +++ b/build/sage_bootstrap/download/mirror_list.py @@ -170,9 +170,7 @@ def _rank_mirrors(self): timed_mirrors = [] import time, socket log.info('Searching fastest mirror') - timeout = socket.getdefaulttimeout() - if timeout is None: - timeout = 1 + timeout = 1 for mirror in self.mirrors: if not mirror.startswith('http'): log.debug('we currently can only handle http, got %s', mirror) @@ -190,6 +188,11 @@ def _rank_mirrors(self): result_ms = int(1000 * result) log.info(str(result_ms).rjust(5) + 'ms: ' + mirror) timed_mirrors.append((result, mirror)) + timed_mirrors.sort() + if len(timed_mirrors) >= 5 and timed_mirrors[4][0] < 0.3: + # We don't need more than 5 decent mirrors + break + if len(timed_mirrors) == 0: # We cannot reach any mirror directly, most likely firewall issue if 'http_proxy' not in os.environ: @@ -197,7 +200,6 @@ def _rank_mirrors(self): raise MirrorListException('Failed to connect to any mirror, probably no internet connection') log.info('Cannot time mirrors via proxy, using default order') else: - timed_mirrors.sort() self._mirrors = [m[1] for m in timed_mirrors] log.info('Fastest mirror: ' + self.fastest)