Skip to content

Commit 3b49e4d

Browse files
mitarnejch
authored andcommitted
fix: also retry HTTP-based transient errors
1 parent 19ab07d commit 3b49e4d

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

gitlab/client.py

+25-11
Original file line numberDiff line numberDiff line change
@@ -675,19 +675,33 @@ def http_request(
675675
json, data, content_type = self._prepare_send_data(files, post_data, raw)
676676
opts["headers"]["Content-type"] = content_type
677677

678+
retry_transient_errors = kwargs.get(
679+
"retry_transient_errors", self.retry_transient_errors
680+
)
678681
cur_retries = 0
679682
while True:
680-
result = self.session.request(
681-
method=verb,
682-
url=url,
683-
json=json,
684-
data=data,
685-
params=params,
686-
timeout=timeout,
687-
verify=verify,
688-
stream=streamed,
689-
**opts,
690-
)
683+
try:
684+
result = self.session.request(
685+
method=verb,
686+
url=url,
687+
json=json,
688+
data=data,
689+
params=params,
690+
timeout=timeout,
691+
verify=verify,
692+
stream=streamed,
693+
**opts,
694+
)
695+
except requests.ConnectionError:
696+
if retry_transient_errors and (
697+
max_retries == -1 or cur_retries < max_retries
698+
):
699+
wait_time = 2 ** cur_retries * 0.1
700+
cur_retries += 1
701+
time.sleep(wait_time)
702+
continue
703+
704+
raise
691705

692706
self._check_redirects(result)
693707

0 commit comments

Comments
 (0)