apache / libcloud

Apache Libcloud is a Python library which hides differences between different cloud provider APIs and allows you to manage different cloud resources through a unified and easy to use API.
https://libcloud.apache.org
Apache License 2.0
2.04k stars 926 forks source link

Retry decorator on RateLimitExceeded issue #1577

Open dimgal1 opened 3 years ago

dimgal1 commented 3 years ago

Summary

Enabling retry logic does not work for rate limit exceeded responses.

Detailed Information

retry decorator expects a RateLimitExceeded error to be raised, though session.request method does not raise an exception if a response is returned by the server no matter the status code.

I've tested it on azure_arm driver by setting RETRY_FAILED_HTTP_REQUESTS to True and trying:

while True:
    nodes = driver.list_nodes()
    print(nodes)

Hitting the throttling limit results in:

  Traceback (most recent call last):
  File "test.py", line 23, in <module>
    nodes = driver.list_nodes()
  File "/home/dimgal/libcloud/libcloud/compute/drivers/azure_arm.py", line 395, in list_nodes
    r = self.connection.request(action,
  File "/home/dimgal/libcloud/libcloud/common/azure_arm.py", line 227, in request
    return super(AzureResourceManagementConnection, self) \
  File "/home/dimgal/libcloud/libcloud/common/base.py", line 655, in request
    response = responseCls(**kwargs)
  File "/home/dimgal/libcloud/libcloud/common/base.py", line 165, in __init__
    raise exception_from_message(code=self.status,
libcloud.common.exceptions.RateLimitReachedError: 429 Rate limit exceeded

urllib3 supports retries based on HTTP status codes, maybe use this? Let me know how you think this should be handled

RunOrVeith commented 3 years ago

I implemented a pull request that goes into the direction of making this more customizable

stale[bot] commented 2 years ago

Thanks for contributing to this issue. As it has been 90 days since the last activity, we are automatically marking is as stale. If this issue is not relevant or applicable anymore (problem has been fixed in a new version or similar), please close the issue or let us know so we can close it. On the contrary, if the issue is still relevant, there is nothing you need to do, but if you have any additional details or context which would help us when working on this issue, please include it as a comment to this issue.