Skip to content

Commit 790e1ef

Browse files
authored
Increase the HTTP requests timeout to 30 in fetch pipes #1144 (#1567)
Signed-off-by: tdruez <[email protected]>
1 parent e4cc635 commit 790e1ef

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

scanpipe/pipes/fetch.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@
4646

4747
Download = namedtuple("Download", "uri directory filename path size sha1 md5")
4848

49+
# Time (in seconds) to wait for the server to send data before giving up.
50+
# The ``REQUEST_CONNECTION_TIMEOUT`` defines:
51+
# - Connect timeout: The maximum time to wait for the client to establish a connection
52+
# to the server.
53+
# - Read timeout: The maximum time to wait for a server response once the connection
54+
# is established.
55+
# Notes: Use caution when lowering this value, as some servers
56+
# (e.g., https://cdn.kernel.org/) may take longer to respond to HTTP requests under
57+
# certain conditions.
58+
HTTP_REQUEST_TIMEOUT = 30
59+
4960

5061
def run_command_safely(command_args):
5162
"""
@@ -107,7 +118,7 @@ def fetch_http(uri, to=None):
107118
path.
108119
"""
109120
request_session = get_request_session(uri)
110-
response = request_session.get(uri, timeout=5)
121+
response = request_session.get(uri, timeout=HTTP_REQUEST_TIMEOUT)
111122

112123
if response.status_code != 200:
113124
raise requests.RequestException
@@ -416,7 +427,7 @@ def check_urls_availability(urls):
416427

417428
request_session = get_request_session(url)
418429
try:
419-
response = request_session.head(url, timeout=5)
430+
response = request_session.head(url, timeout=HTTP_REQUEST_TIMEOUT)
420431
response.raise_for_status()
421432
except requests.exceptions.RequestException:
422433
errors.append(url)

0 commit comments

Comments
 (0)