Skip to content

Async version of Connection does not use retry mechanism #2211

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

Closed
szumka opened this issue Jun 2, 2022 · 4 comments
Closed

Async version of Connection does not use retry mechanism #2211

szumka opened this issue Jun 2, 2022 · 4 comments

Comments

@szumka
Copy link
Contributor

szumka commented Jun 2, 2022

Version: redis-py: 4.3.1

Description: Missing call_with_retry mechanism in async version of Connection (and SentinelManagedConnection). This behavior differs from the sync version of those classes.

test to reproduce the issue:

import socket

import pytest

from redis.asyncio.retry import Retry
from redis.asyncio.sentinel import SentinelManagedConnection
from redis.backoff import NoBackoff

from .compat import mock

pytestmark = pytest.mark.asyncio


async def test_connect_retry_on_timeout_error():
    """Test that the _connect function is retried in case of a timeout"""
    connection_pool = mock.AsyncMock()
    connection_pool.get_master_address = mock.AsyncMock(return_value=("localhost", 6379))
    conn = SentinelManagedConnection(retry_on_timeout=True, retry=Retry(NoBackoff(), 3), connection_pool=connection_pool)
    origin_connect = conn._connect
    conn._connect = mock.AsyncMock()

    async def mock_connect():
        # connect only on the last retry
        if conn._connect.call_count <= 2:
            raise socket.timeout
        else:
            return await origin_connect()

    conn._connect.side_effect = mock_connect
    await conn.connect()
    assert conn._connect.call_count == 3
@dvora-h
Copy link
Collaborator

dvora-h commented Jun 23, 2022

@szumka Is this issue still relevant or #2180 fixes it?

@szumka
Copy link
Contributor Author

szumka commented Jun 24, 2022

@dvora-h The same issue still ocured - reproduced on the newest version of redis-py (commit 63cf7ec)

@jonathansp
Copy link

Still happening in 4.3.4

  File "...python3.9/site-packages/redis/asyncio/retry.py", line 59, in call_with_retry
    return await do()
  File "...python3.9/site-packages/redis/asyncio/client.py", line 462, in _send_command_parse_response
    await conn.send_command(*args)
  File "...python3.9/site-packages/redis/asyncio/connection.py", line 905, in send_command
    await self.send_packed_command(
  File ".../site-packages/redis/asyncio/connection.py", line 896, in send_packed_command
    raise ConnectionError(...

redis.exceptions.ConnectionError: Error UNKNOWN while writing to socket. Connection lost.

@dvora-h
Copy link
Collaborator

dvora-h commented Jul 21, 2022

Closed because it was fixed in # 2271

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

No branches or pull requests

3 participants