Skip to content

Commit 9998bfd

Browse files
committed
Fix #1128 - Add timeout and clean up log for http_client
For unreachable hosts, the exception handler was triggered, but at the same time the request did not return. Adding a timeout to requests calls fixed this.
1 parent 433239b commit 9998bfd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

checks/http_client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ def _do_request(args, headers, kwargs, session, url):
2828
following the redirect chain, then ensures response.history is complete.
2929
"""
3030
user_allow_redirects = kwargs.pop("allow_redirects", True)
31-
response = session.get(url, headers=headers, stream=True, allow_redirects=False, *args, **kwargs)
31+
response = session.get(
32+
url, headers=headers, stream=True, allow_redirects=False, timeout=DEFAULT_TIMEOUT, *args, **kwargs
33+
)
3234
if response.next and user_allow_redirects:
3335
headers.pop("Host", None)
3436
initial_response = response
3537
response = session.get(
36-
initial_response.next.url, headers=headers, stream=True, allow_redirects=True, *args, **kwargs
38+
initial_response.next.url,
39+
headers=headers,
40+
stream=True,
41+
allow_redirects=True,
42+
timeout=DEFAULT_TIMEOUT,
43+
*args,
44+
**kwargs,
3745
)
3846
response.history.insert(0, initial_response)
3947

@@ -62,7 +70,7 @@ def http_get(
6270
try:
6371
response = _do_request(args, headers, kwargs, session, url)
6472
except requests.RequestException as exc:
65-
log.debug(f"HTTP request raised exception: {url} (headers: {headers}): {exc}", exc_info=exc)
73+
log.debug(f"HTTP request raised exception: {url} (headers: {headers}): {exc}")
6674
raise exc
6775

6876
log.debug(f"HTTP request completed in {timer()-start_time:.06f}s: {url} (headers: {headers})")

0 commit comments

Comments
 (0)