Release: retry transient asset verification failures
This commit is contained in:
2 files changed
+59
-12
No files matched your search
+27
-12
@@ -15,6 +15,7 @@ import re
|
||||
import secrets
|
||||
import stat
|
||||
import sys
|
||||
import time
|
||||
from typing import Any, NoReturn
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import quote, urlencode, urljoin, urlsplit
|
||||
@@ -228,18 +229,32 @@ class GiteaApi:
|
||||
):
|
||||
fail(f"Gitea returned an untrusted asset URL: {download_url!r}")
|
||||
request = Request(target, headers=self.headers, method="GET")
|
||||
result = hashlib.sha256()
|
||||
size = 0
|
||||
try:
|
||||
with self._opener.open(request, timeout=self._timeout_seconds) as response:
|
||||
if response.status != 200:
|
||||
fail(f"downloading an asset returned HTTP {response.status}")
|
||||
while chunk := response.read(UPLOAD_CHUNK_BYTES):
|
||||
size += len(chunk)
|
||||
result.update(chunk)
|
||||
except (HTTPError, OSError, URLError) as error:
|
||||
fail(f"downloading an asset for verification failed: {error}")
|
||||
return size, result.hexdigest()
|
||||
for attempt in range(4):
|
||||
result = hashlib.sha256()
|
||||
size = 0
|
||||
try:
|
||||
with self._opener.open(
|
||||
request, timeout=self._timeout_seconds
|
||||
) as response:
|
||||
if response.status != 200:
|
||||
fail(
|
||||
"downloading an asset returned "
|
||||
f"HTTP {response.status}"
|
||||
)
|
||||
while chunk := response.read(UPLOAD_CHUNK_BYTES):
|
||||
size += len(chunk)
|
||||
result.update(chunk)
|
||||
return size, result.hexdigest()
|
||||
except HTTPError as error:
|
||||
fail(f"downloading an asset for verification failed: {error}")
|
||||
except (OSError, URLError) as error:
|
||||
if attempt == 3:
|
||||
fail(
|
||||
"downloading an asset for verification failed "
|
||||
f"after retries: {error}"
|
||||
)
|
||||
time.sleep(2**attempt)
|
||||
raise AssertionError("unreachable")
|
||||
|
||||
|
||||
def quote_owner(value: str) -> str:
|
||||
|
||||
Reference in new issue
Block a user