Skip to content

Commit

Permalink
Add retry for urlopen
Browse files Browse the repository at this point in the history
Many a times open url returns errors including 503,
handling it by introducing retries.

Signed-off-by: Srikanth Aithal <srikanth.aithal@amd.com>
  • Loading branch information
Srikanth Aithal committed Dec 3, 2024
1 parent 5b65f4f commit 1ecfb47
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions avocado/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ def url_open(url, data=None, timeout=5):
:return: file-like object.
:raises: `URLError`.
"""
try:
result = urlopen(url, data=data, timeout=timeout)
except (socket.timeout, HTTPError) as ex:
msg = f"Failed downloading file: {str(ex)}"
log.error(msg)
retry_attempt = 0
while retry_attempt < 10:
try:
result = urlopen(url, data=data, timeout=timeout)
break
except (socket.timeout, HTTPError) as ex:
msg = f"Failed downloading file: {str(ex)}"
log.error(msg)
retry_attempt += 1
msg = f"retry attempt: {retry_attempt}"
log.debug(msg)

Check warning on line 57 in avocado/utils/download.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/download.py#L53-L57

Added lines #L53 - L57 were not covered by tests
if "result" not in locals():
return None

msg = (
Expand Down

0 comments on commit 1ecfb47

Please sign in to comment.