Skip to content

Commit c22428c

Browse files
committed
feat(client): additionally handle retries for request timeouts
1 parent a4cbecb commit c22428c

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

docs/api-usage-advanced.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ python-gitlab can automatically retry in such case, when
147147
``retry_transient_errors`` argument is set to ``True``. When enabled,
148148
HTTP error codes 500 (Internal Server Error), 502 (502 Bad Gateway),
149149
503 (Service Unavailable), 504 (Gateway Timeout), and Cloudflare
150-
errors (520-530) are retried.
150+
errors (520-530) are retried. `requests.exceptions.Timeout` are also
151+
handled.
151152

152153
Additionally, HTTP error code 409 (Conflict) is retried if the reason
153154
is a

gitlab/client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Gitlab:
6060
order_by: Set order_by globally
6161
user_agent: A custom user agent to use for making HTTP requests.
6262
retry_transient_errors: Whether to retry after 500, 502, 503, 504
63-
or 52x responses. Defaults to False.
63+
or 52x responses, or after a request timeout. Defaults to False.
6464
keep_base_url: keep user-provided base URL for pagination if it
6565
differs from response headers
6666
@@ -665,7 +665,7 @@ def http_request(
665665
obey_rate_limit: Whether to obey 429 Too Many Request
666666
responses. Defaults to True.
667667
retry_transient_errors: Whether to retry after 500, 502, 503, 504
668-
or 52x responses. Defaults to False.
668+
or 52x responses, or after a request timeout. Defaults to False.
669669
max_retries: Max retries after 429 or transient errors,
670670
set to -1 to retry forever. Defaults to 10.
671671
extra_headers: Add and override HTTP headers for the request.
@@ -737,7 +737,11 @@ def http_request(
737737
stream=streamed,
738738
**opts,
739739
)
740-
except (requests.ConnectionError, requests.exceptions.ChunkedEncodingError):
740+
except (
741+
requests.ConnectionError,
742+
requests.exceptions.ChunkedEncodingError,
743+
requests.exceptions.Timeout,
744+
):
741745
if retry.handle_retry():
742746
continue
743747
raise

tests/unit/test_gitlab_http_methods.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def test_http_request_extra_headers(gl):
146146
[
147147
requests.ConnectionError("Connection aborted."),
148148
requests.exceptions.ChunkedEncodingError("Connection broken."),
149+
requests.exceptions.Timeout("Request timed out."),
149150
],
150151
)
151152
def test_http_request_with_retry_on_method_for_transient_network_failures(

0 commit comments

Comments
 (0)