Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry for urlopen #6077

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
: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
Loading