8000 Mask network issues by ludeeus · Pull Request #2616 · hacs/integration · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Mask network issues #2616

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

Merged
merged 1 commit into from
Apr 13, 2022
Merged
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
54 changes: 33 additions & 21 deletions custom_components/hacs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,30 +598,42 @@ async def async_download_file(self, url: str, *, headers: dict | None = None) ->
url = url.replace("tags/", "")

self.log.debug("Downloading %s", url)
timeouts = 0

try:
request = await self.session.get(
url=url,
timeout=ClientTimeout(total=60),
headers=headers,
)
while timeouts < 5:
try:
request = await self.session.get(
url=url,
timeout=ClientTimeout(total=60),
headers=headers,
)

# Make sure that we got a valid result
if request.status == 200:
return await request.read()

raise HacsException(f"Got status code {request.status} when trying to download {url}")
except asyncio.TimeoutError:
self.log.error(
"A timeout of 60! seconds was encountered while downloading %s, "
"check the network on the host running Home Assistant. This is "
"not a problem with HACS but how your host communicates with GitHub",
url,
)
except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except
self.log.exception("Download failed - %s", exception)
# Make sure that we got a valid result
if request.status == 200:
return await request.read()

return None
raise HacsException(
f"Got status code {request.status} when trying to download {url}"
)
except asyncio.TimeoutError:
self.log.warning(
"A timeout of 60! seconds was encountered while downloading %s, "
"using over 60 seconds to download a single file is not normal. "
"This is not a problem with HACS but how your host communicates with GitHub. "
"Retrying up to 5 times to mask/hide your host/network problems to "
"stop the flow of issues opened about it. "
"Tries left %s",
url,
(4 - timeouts),
)
timeouts += 1
await asyncio.sleep(1)
continue

except BaseException as exception: # lgtm [py/catch-base-exception] pylint: disable=broad-except
self.log.exception("Download failed - %s", exception)

return None

async def async_recreate_entities(self) -> None:
"""Recreate entities."""
Expand Down
0