8000 library does not retry on 504 timeout errors · Issue #525 · massive-com/client-python · GitHub
[go: up one dir, main page]

Skip to content

library does not retry on 504 timeout errors #525

@kartiksubbarao

Description

@kartiksubbarao

Describe the bug
Even with retries=10 specified when creating the client object, the library doesn't seem to retry on 504 timeout errors. For example, a couple times last week I got a polygon.exceptions.BadResponse exception:

  File "/path/to/lib64/python3.11/site-packages/polygon/rest/base.py", line 192, in _paginate_iter
    resp = self._get(
           ^^^^^^^^^^
  File "/path/to/lib64/python3.11/site-packages/polygon/rest/base.py", line 110, in _get
    raise BadResponse(resp.data.decode("utf-8"))
polygon.exceptions.BadResponse: <html>
<head><title>504 Gateway Time-out</title></head>
<body>
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx/1.19.2</center>
</body>
</html>

The core issue I think is that polygon's retry logic only retries for the default set of codes that urllib3 recognizes for retries (413, 429, 503). Adding 504 could be a simple fix.

Just FYI for anyone else who is seeing this issue -- I'm currently using the tenacity library as a workaround:

def is_504(exception):
    return isinstance(exception, polygon.exceptions.BadResponse) \
        and '504 Gateway Time-out' in str(exception)
polygon_retry = tenacity.retry(retry=(tenacity.retry_if_exception(is_504)),
    stop=tenacity.stop_after_attempt(10))

And then using @polygon_retry as a decorator for functions that call polygon library methods.

To Reproduce
It's difficult to reproduce this problem since it doesn't happen very often. One way to reproduce it might be to create a mock API server that returns 504s.

Expected behavior
Expected behavior is for the polygon library to handle the timeout itself (based on the retries argument).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0