Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

library does not retry on 504 timeout errors #525

Copy link
Copy link
@kartiksubbarao

Description

@kartiksubbarao
Issue body actions

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 workingSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.