Skip to content

Commit

Permalink
Retry on more statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Oct 11, 2021
1 parent a645152 commit f5957fa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions dandi/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,7 @@

#: The identifier for draft Dandiset versions
DRAFT = "draft"

#: HTTP response status codes that should always be retried (until we run out
#: of retries)
RETRY_STATUSES = (500, 502, 503, 504)
5 changes: 3 additions & 2 deletions dandi/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from .consts import (
DRAFT,
MAX_CHUNK_SIZE,
RETRY_STATUSES,
DandiInstance,
known_instances,
known_instances_rev,
Expand Down Expand Up @@ -151,7 +152,7 @@ def request(
:type json_resp: bool
:param retry_statuses: a sequence of HTTP response status codes to
retry; 503 will be added to this set
retry in addition to `dandi.consts.RETRY_STATUSES`
"""

url = self.get_url(path)
Expand Down Expand Up @@ -191,7 +192,7 @@ def request(
headers=headers,
**kwargs,
)
if result.status_code in [503, *retry_statuses]:
if result.status_code in [*RETRY_STATUSES, *retry_statuses]:
result.raise_for_status()
except Exception:
lgr.exception("HTTP connection failed")
Expand Down
4 changes: 2 additions & 2 deletions dandi/dandiarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import requests

from . import get_logger
from .consts import VERSION_REGEX, known_instances
from .consts import RETRY_STATUSES, VERSION_REGEX, known_instances
from .dandiapi import BaseRemoteAsset, DandiAPIClient, RemoteDandiset
from .exceptions import FailedToConnectError, NotFoundError, UnknownURLError
from .utils import get_instance
Expand Down Expand Up @@ -526,7 +526,7 @@ def follow_redirect(url):
i = 0
while True:
r = requests.head(url, allow_redirects=True)
if r.status_code in (400, 502, 503, 504) and i < 5:
if r.status_code in (400, *RETRY_STATUSES) and i < 5:
sleep(0.1 * 10 ** i)
i += 1
continue
Expand Down
4 changes: 2 additions & 2 deletions dandi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import requests

from . import get_logger
from .consts import dandiset_metadata_file
from .consts import RETRY_STATUSES, dandiset_metadata_file
from .dandiarchive import DandisetURL, MultiAssetURL, SingleAssetURL, parse_dandi_url
from .dandiset import Dandiset
from .support.digests import get_digest
Expand Down Expand Up @@ -566,7 +566,7 @@ def _download_file(
if attempt >= 2 or exc.response.status_code not in (
400, # Bad Request, but happened with gider:
# https://github.com/dandi/dandi-cli/issues/87
503, # Service Unavailable
*RETRY_STATUSES,
):
lgr.debug("Download failed: %s", exc)
yield {"status": "error", "message": str(exc)}
Expand Down

0 comments on commit f5957fa

Please sign in to comment.