Skip to content

Commit

Permalink
Retry requests on ConnectionErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Mar 1, 2021
1 parent fa890fd commit 944921b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions dandi/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .consts import MAX_CHUNK_SIZE, known_instances_rev
from .girder import keyring_lookup
from . import get_logger
from .utils import USER_AGENT
from .utils import USER_AGENT, try_multiple

lgr = get_logger()

Expand Down Expand Up @@ -132,14 +132,22 @@ def send_request(

lgr.debug("%s %s", method.upper(), url)
try:
result = f(
url,
params=parameters,
data=data,
files=files,
json=json,
headers=_headers,
**kwargs,
# urllib3's ConnectionPool isn't thread-safe, so we sometimes hit
# ConnectionErrors on the start of an upload. Retry when this
# happens. Cf. <https://github.com/urllib3/urllib3/issues/951>.
result = try_multiple(
5,
requests.ConnectionError,
1.1,
lambda: f(
url,
params=parameters,
data=data,
files=files,
json=json,
headers=_headers,
**kwargs,
),
)
except Exception:
lgr.exception("HTTP connection failed")
Expand Down

0 comments on commit 944921b

Please sign in to comment.