Skip to content

Commit

Permalink
feat(client): automatically retry on HTTP 409 Resource lock
Browse files Browse the repository at this point in the history
  • Loading branch information
pspacek authored and nejch committed Dec 5, 2022
1 parent 985b971 commit 4edc2c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions docs/api-usage-advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ GitLab server can sometimes return a transient HTTP error.
python-gitlab can automatically retry in such case, when
``retry_transient_errors`` argument is set to ``True``. When enabled,
HTTP error codes 500 (Internal Server Error), 502 (502 Bad Gateway),
503 (Service Unavailable), and 504 (Gateway Timeout) are retried. It will retry until reaching
the ``max_retries`` value. By default, ``retry_transient_errors`` is set to ``False`` and an exception
is raised for these errors.
503 (Service Unavailable), and 504 (Gateway Timeout) are retried.
Additionally the HTTP error code 409 (Conflict) is retried if the text message
mentions "Resource lock". It will retry until reaching the ``max_retries``
value. By default, ``retry_transient_errors`` is set to ``False`` and an
exception is raised for these errors.

.. code-block:: python
Expand Down
5 changes: 4 additions & 1 deletion gitlab/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,10 @@ def http_request(
return result

if (429 == result.status_code and obey_rate_limit) or (
result.status_code in RETRYABLE_TRANSIENT_ERROR_CODES
(
result.status_code in RETRYABLE_TRANSIENT_ERROR_CODES
or (result.status_code == 409 and "Resource lock" in result.reason)
)
and retry_transient_errors
):
# Response headers documentation:
Expand Down

0 comments on commit 4edc2c2

Please sign in to comment.