aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-01-17 23:02:17 -0500
committerJussi Pakkanen <jpakkane@gmail.com>2022-01-18 16:47:05 +0200
commit4b9ec4f6d50db7f408f7910299846dfae6cb9559 (patch)
tree6ee2c2e5e95b9b91b8b01b8282b998c9bd5a390e /mesonbuild
parent7deeb293b684e6361fee28e1ec34adce693969b4 (diff)
downloadmeson-4b9ec4f6d50db7f408f7910299846dfae6cb9559.zip
meson-4b9ec4f6d50db7f408f7910299846dfae6cb9559.tar.gz
meson-4b9ec4f6d50db7f408f7910299846dfae6cb9559.tar.bz2
wraps: implement exponential backoff for downloading files
Implementation modeled after mesonlib.windows_proof_rmtree(). Implements the other half of #9688
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/wrap/wrap.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index 24b0a42..c99e33c 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -26,6 +26,7 @@ import stat
import subprocess
import sys
import configparser
+import time
import typing as T
import textwrap
@@ -534,12 +535,22 @@ class Resolver:
if dhash != expected:
raise WrapException(f'Incorrect hash for {what}:\n {expected} expected\n {dhash} actual.')
+ def get_data_with_backoff(self, urlstring: str) -> T.Tuple[str, str]:
+ delays = [1, 2, 4, 8, 16]
+ for d in delays:
+ try:
+ return self.get_data(urlstring)
+ except Exception as e:
+ mlog.warning(f'failed to download with error: {e}. Trying after a delay...', fatal=False)
+ time.sleep(d)
+ return self.get_data(urlstring)
+
def download(self, what: str, ofname: str, fallback: bool = False) -> None:
self.check_can_download()
srcurl = self.wrap.get(what + ('_fallback_url' if fallback else '_url'))
mlog.log('Downloading', mlog.bold(self.packagename), what, 'from', mlog.bold(srcurl))
try:
- dhash, tmpfile = self.get_data(srcurl)
+ dhash, tmpfile = self.get_data_with_backoff(srcurl)
expected = self.wrap.get(what + '_hash').lower()
if dhash != expected:
os.remove(tmpfile)