Skip to content

Commit 8f4a406

Browse files
author
Release Manager
committed
sagemathgh-36565: Limit wait for slow mirrors Using a timeout of 1 second unconditionally, stopping when 5 good mirrors (300ms ping) are found <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> Fixes sagemath#34411 <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36565 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee, Matthias Köppe
2 parents 7d60e6e + b6c05e0 commit 8f4a406

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

build/sage_bootstrap/download/mirror_list.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ def _rank_mirrors(self):
170170
timed_mirrors = []
171171
import time, socket
172172
log.info('Searching fastest mirror')
173-
timeout = socket.getdefaulttimeout()
174-
if timeout is None:
175-
timeout = 1
173+
timeout = 1
176174
for mirror in self.mirrors:
177175
if not mirror.startswith('http'):
178176
log.debug('we currently can only handle http, got %s', mirror)
@@ -190,14 +188,18 @@ def _rank_mirrors(self):
190188
result_ms = int(1000 * result)
191189
log.info(str(result_ms).rjust(5) + 'ms: ' + mirror)
192190
timed_mirrors.append((result, mirror))
191+
timed_mirrors.sort()
192+
if len(timed_mirrors) >= 5 and timed_mirrors[4][0] < 0.3:
193+
# We don't need more than 5 decent mirrors
194+
break
195+
193196
if len(timed_mirrors) == 0:
194197
# We cannot reach any mirror directly, most likely firewall issue
195198
if 'http_proxy' not in os.environ:
196199
log.error('Could not reach any mirror directly and no proxy set')
197200
raise MirrorListException('Failed to connect to any mirror, probably no internet connection')
198201
log.info('Cannot time mirrors via proxy, using default order')
199202
else:
200-
timed_mirrors.sort()
201203
self._mirrors = [m[1] for m in timed_mirrors]
202204
log.info('Fastest mirror: ' + self.fastest)
203205

0 commit comments

Comments
 (0)