[gimp-web/wip/Jehan/fix-ci] tools: test timing out?




commit 37f211ae9457e463efdfbe84615f83e2dcf3da7a
Author: Jehan <jehan girinstud io>
Date:   Mon May 2 17:37:11 2022 +0200

    tools: test timing out?

 tools/downloads/gimp-check-mirrors.py | 76 ++++++++++++++++++++---------------
 1 file changed, 44 insertions(+), 32 deletions(-)
---
diff --git a/tools/downloads/gimp-check-mirrors.py b/tools/downloads/gimp-check-mirrors.py
index 8c3766a2..babc379e 100755
--- a/tools/downloads/gimp-check-mirrors.py
+++ b/tools/downloads/gimp-check-mirrors.py
@@ -98,39 +98,51 @@ def verify_remote(uri, future):
   success     = False
   status      = None
   checksum_ok = None
-  try:
-    if future is not None:
-      headers = {'user-agent': 'Mozilla/5.0'}
-      with requests.get(uri, headers=headers, stream=True) as response:
-        m = hashlib.sha256()
-        # I don't think the chunk_size is useful, since docs
-        # says that "stream=True will read data as it arrives
-        # in whatever size the chunks are received" which is
-        # the ideal way. But if it doesn't, let's use 2**16 as
-        # a reasonable chunk size to process.
-        for line in response.iter_content(chunk_size=65536, decode_unicode=False):
-          m.update(line)
-        if m.digest() == future.result():
-          checksum_ok = True
-          success = True
-        else:
-          checksum_ok = False
+  tries       = 3
+  while tries > 0:
+    tries -= 1
+    try:
+      if future is not None:
+        headers = {'user-agent': 'Mozilla/5.0'}
+        with requests.get(uri, headers=headers, stream=True, timeout=10) as response:
+          m = hashlib.sha256()
+          # I don't think the chunk_size is useful, since docs
+          # says that "stream=True will read data as it arrives
+          # in whatever size the chunks are received" which is
+          # the ideal way. But if it doesn't, let's use 2**16 as
+          # a reasonable chunk size to process.
+          for line in response.iter_content(chunk_size=65536, decode_unicode=False):
+            m.update(line)
+          if m.digest() == future.result():
+            checksum_ok = True
+            success = True
+          else:
+            checksum_ok = False
+          status = str(response.status_code)
+      else:
+        response = requests.head(url=uri, timeout=20, allow_redirects=True)
         status = str(response.status_code)
-    else:
-      response = requests.head(url=uri, timeout=20, allow_redirects=True)
-      status = str(response.status_code)
-      if response.status_code == 200:
-        success = True
-  except requests.exceptions.ConnectionError as error:
-    status = 'Connection error'
-  except requests.exceptions.ConnectTimeout as error:
-    status = 'Connection timed out'
-  except requests.exceptions.ReadTimeout as error:
-    status = 'Read timed out'
-  except requests.exceptions.TooManyRedirects as error:
-    status = 'Too many redirects'
-  except OSError as error:
-    status = str(error.strerror)
+        if response.status_code == 200:
+          success = True
+      # Exit the loop.
+      break
+    # This API apparently doesn't like interruption of network and ends
+    # up waiting forever in some cases. Let's retry in such case.
+    except requests.exceptions.ConnectTimeout as error:
+      status = 'Connection timed out'
+      print("{}: RETRYING {}".format(status, uri))
+    except requests.exceptions.ReadTimeout as error:
+      status = 'Read timed out'
+      print("{}: RETRYING {}".format(status, uri))
+    except requests.exceptions.ConnectionError as error:
+      status = 'Connection error'
+      break
+    except requests.exceptions.TooManyRedirects as error:
+      status = 'Too many redirects'
+      break
+    except OSError as error:
+      status = str(error.strerror)
+      break
 
   return uri, success, status, checksum_ok
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]