Skip to content

Commit 4060146

Browse files
fix: support RateLimit-Reset header
Some endpoints are not returning the `Retry-After` header when rate-limiting occurrs. In those cases use the `RateLimit-Reset` [1] header, if available. Closes: #1889 [1] https://docs.gitlab.com/ee/user/admin_area/settings/user_and_ip_rate_limits.html#response-headers
1 parent 85a734f commit 4060146

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

gitlab/client.py

+4
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,14 @@ def http_request(
700700
if (429 == result.status_code and obey_rate_limit) or (
701701
result.status_code in [500, 502, 503, 504] and retry_transient_errors
702702
):
703+
# Response headers documentation:
704+
# https://docs.gitlab.com/ee/user/admin_area/settings/user_and_ip_rate_limits.html#response-headers
703705
if max_retries == -1 or cur_retries < max_retries:
704706
wait_time = 2 ** cur_retries * 0.1
705707
if "Retry-After" in result.headers:
706708
wait_time = int(result.headers["Retry-After"])
709+
elif "RateLimit-Reset" in result.headers:
710+
wait_time = int(result.headers["RateLimit-Reset"]) - time.time()
707711
cur_retries += 1
708712
time.sleep(wait_time)
709713
continue

0 commit comments

Comments
 (0)