Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): use async Retry #2555

Merged
merged 1 commit into from May 9, 2024
Merged

Conversation

klaemo
Copy link
Contributor

@klaemo klaemo commented May 3, 2024

After a lot of trial and error on why connection errors don't seem to get retried (#2542), I found this to be the culprit.

You can verify it with the following script. Start running it, then kill your redis instance.

  • With redis.asyncio.retry it will not crash and restart pinging when redis comes back
  • With redis.retry it will crash
import os
import asyncio
import redis.asyncio as aioredis
from redis.backoff import ExponentialBackoff
# switch the following lines to test the behavior difference
# from redis.retry import Retry
from redis.asyncio.retry import Retry

from redis.exceptions import (BusyLoadingError, ConnectionError, TimeoutError)

retry = Retry(ExponentialBackoff(cap=20, base=1), 20)
retry_errors = [BusyLoadingError, ConnectionError, TimeoutError]
redis_connection = aioredis.from_url(os.environ.get('REDIS_URI', 'redis://localhost:6379'),
                                  decode_responses=True,
                                  retry=retry,
                                  retry_on_error=retry_errors,
                                  health_check_interval=30)

async def run():
    while True:
        print(await redis_connection.ping())
        await asyncio.sleep(1)

asyncio.run(run())

Unfortunately, there's no proper type checking for kwargs in redis.from_url. I only found out about the difference by playing with the Redis constructor and there it yelled at me that the types for retry are incompatible.

Copy link
Collaborator

@roggervalf roggervalf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@roggervalf roggervalf merged commit d6dd21d into taskforcesh:master May 9, 2024
11 checks passed
github-actions bot pushed a commit that referenced this pull request May 16, 2024
## [5.7.9](v5.7.8...v5.7.9) (2024-05-16)

### Bug Fixes

* **connection:** use async Retry ([#2555](#2555)) [python] ([d6dd21d](d6dd21d))
* **job:** validate job existence when adding a log ([#2562](#2562)) ([f87e3fe](f87e3fe))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants