Browse Source

using urlopen() with explicit timeout

Andrei Antonov 9 months ago
parent
commit
8f7781f1d6
3 changed files with 8 additions and 6 deletions
  1. 3
    2
      ghwt.py
  2. 1
    1
      manual tests/4 standalone binaries/build_windows_package.py
  3. 4
    3
      mesonbuild/wrap/wrap.py

+ 3
- 2
ghwt.py View File

@@ -22,10 +22,11 @@
22 22
 import urllib.request, json, sys, os, shutil, subprocess
23 23
 import configparser, hashlib
24 24
 
25
+req_timeout = 600.0
25 26
 private_repos = {'meson', 'wrapweb', 'meson-ci'}
26 27
 
27 28
 def gh_get(url):
28
-    r = urllib.request.urlopen(url)
29
+    r = urllib.request.urlopen(url, timeout=req_timeout)
29 30
     jd = json.loads(r.read().decode('utf-8'))
30 31
     return jd
31 32
 
@@ -45,7 +46,7 @@ def unpack(sproj, branch, outdir):
45 46
     config = configparser.ConfigParser()
46 47
     config.read(usfile)
47 48
     us_url = config['wrap-file']['source_url']
48
-    us = urllib.request.urlopen(us_url).read()
49
+    us = urllib.request.urlopen(us_url, timeout=req_timeout).read()
49 50
     h = hashlib.sha256()
50 51
     h.update(us)
51 52
     dig = h.hexdigest()

+ 1
- 1
manual tests/4 standalone binaries/build_windows_package.py View File

@@ -11,7 +11,7 @@ shutil.rmtree('build', ignore_errors=True)
11 11
 os.mkdir('build')
12 12
 
13 13
 if not os.path.exists(sdl_filename):
14
-    response = urllib.request.urlopen(sdl_url)
14
+    response = urllib.request.urlopen(sdl_url, timeout=600.0)
15 15
     data = response.read()
16 16
     open(sdl_filename, 'wb').write(data)
17 17
 

+ 4
- 3
mesonbuild/wrap/wrap.py View File

@@ -29,6 +29,7 @@ except ImportError:
29 29
     has_ssl = False
30 30
     API_ROOT = 'http://wrapdb.mesonbuild.com/v1/'
31 31
 
32
+req_timeout = 600.0
32 33
 ssl_warning_printed = False
33 34
 
34 35
 def build_ssl_context():
@@ -51,7 +52,7 @@ def open_wrapdburl(urlstring):
51 52
     global ssl_warning_printed
52 53
     if has_ssl:
53 54
         try:
54
-            return urllib.request.urlopen(urlstring)# , context=build_ssl_context())
55
+            return urllib.request.urlopen(urlstring, timeout=req_timeout)# , context=build_ssl_context())
55 56
         except urllib.error.URLError:
56 57
             if not ssl_warning_printed:
57 58
                 print('SSL connection failed. Falling back to unencrypted connections.')
@@ -64,7 +65,7 @@ def open_wrapdburl(urlstring):
64 65
     # certificate is not known.
65 66
     if urlstring.startswith('https'):
66 67
         urlstring = 'http' + urlstring[5:]
67
-    return urllib.request.urlopen(urlstring)
68
+    return urllib.request.urlopen(urlstring, timeout=req_timeout)
68 69
 
69 70
 
70 71
 class PackageDefinition:
@@ -270,7 +271,7 @@ class Resolver:
270 271
         if url.startswith('https://wrapdb.mesonbuild.com'):
271 272
             resp = open_wrapdburl(url)
272 273
         else:
273
-            resp = urllib.request.urlopen(url)
274
+            resp = urllib.request.urlopen(url, timeout=req_timeout)
274 275
         with contextlib.closing(resp) as resp:
275 276
             try:
276 277
                 dlsize = int(resp.info()['Content-Length'])

Loading…
Cancel
Save