Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Release Manager committed Oct 31, 2023
2 parents 7d60e6e + b6c05e0 commit 8f4a406
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions build/sage_bootstrap/download/mirror_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -190,14 +188,18 @@ 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:
log.error('Could not reach any mirror directly and no proxy set')
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)

Expand Down

0 comments on commit 8f4a406

Please sign in to comment.