summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2022-12-21 19:40:26 +0100
committerGitHub <noreply@github.com>2022-12-21 19:40:26 +0100
commit4a22c1c699d4684db6a154fc8584d1533273c208 (patch)
tree62016b6792d383f0c4a26b64ec7ef8a945573abb /lib
parentf021479ef0ca9ef6c05d193d4d0017984b752573 (diff)
downloadspack-4a22c1c699d4684db6a154fc8584d1533273c208.tar.gz
spack-4a22c1c699d4684db6a154fc8584d1533273c208.tar.bz2
spack-4a22c1c699d4684db6a154fc8584d1533273c208.tar.xz
spack-4a22c1c699d4684db6a154fc8584d1533273c208.zip
urlopen: handle timeout in opener (#34639)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/util/web.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/spack/spack/util/web.py b/lib/spack/spack/util/web.py
index 90232f7fe1..e004b30c4f 100644
--- a/lib/spack/spack/util/web.py
+++ b/lib/spack/spack/util/web.py
@@ -50,9 +50,10 @@ def _urlopen():
without_ssl = build_opener(s3, gcs, HTTPSHandler(context=ssl._create_unverified_context()))
# And dynamically dispatch based on the config:verify_ssl.
- def dispatch_open(*args, **kwargs):
+ def dispatch_open(fullurl, data=None, timeout=None):
opener = with_ssl if spack.config.get("config:verify_ssl", True) else without_ssl
- return opener.open(*args, **kwargs)
+ timeout = timeout or spack.config.get("config:connect_timeout", 10)
+ return opener.open(fullurl, data, timeout)
return dispatch_open
@@ -89,11 +90,10 @@ def read_from_url(url, accept_content_type=None):
url = urllib.parse.urlparse(url)
# Timeout in seconds for web requests
- timeout = spack.config.get("config:connect_timeout", 10)
request = Request(url.geturl(), headers={"User-Agent": SPACK_USER_AGENT})
try:
- response = urlopen(request, timeout=timeout)
+ response = urlopen(request)
except URLError as err:
raise SpackWebError("Download failed: {}".format(str(err)))