From 9af09a2b30da522956174f339a182710d748cb94 Mon Sep 17 00:00:00 2001 From: Mitar Date: Wed, 20 Oct 2021 22:41:38 +0200 Subject: [PATCH] fix: also retry HTTP-based transient errors --- gitlab/client.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gitlab/client.py b/gitlab/client.py index 8bec64f24..009b1543b 100644 --- a/gitlab/client.py +++ b/gitlab/client.py @@ -609,18 +609,29 @@ def http_request( prepped.url, {}, streamed, verify, None ) + retry_transient_errors = kwargs.get( + "retry_transient_errors", self.retry_transient_errors + ) cur_retries = 0 while True: - result = self.session.send(prepped, timeout=timeout, **settings) + try: + result = self.session.send(prepped, timeout=timeout, **settings) + except requests.ConnectionError: + if retry_transient_errors and ( + max_retries == -1 or cur_retries < max_retries + ): + wait_time = 2 ** cur_retries * 0.1 + cur_retries += 1 + time.sleep(wait_time) + continue + + raise self._check_redirects(result) if 200 <= result.status_code < 300: return result - retry_transient_errors = kwargs.get( - "retry_transient_errors", self.retry_transient_errors - ) if (429 == result.status_code and obey_rate_limit) or ( result.status_code in [500, 502, 503, 504] and retry_transient_errors ):