Description
Describe the bug
When trying to use a AsyncRedisManager with a Redis Sentinel config a TimeoutError occurs
To Reproduce
import socketio
from socketio import AsyncServer
from socketio import AsyncRedisManager
app = FastAPI()
url = (
"redis+sentinel://"
"h1.net:26379,"
"h2.net:26379,"
"h3.net:26379"
"/0/mymaster"
)
mgr = AsyncRedisManager(
url,
redis_options={
"username": "...",
"password": "...",
"ssl": True,
"sentinel_kwargs": {"ssl": True},
"socket_timeout": 5,
"socket_connect_timeout": 5,
},
)
sio = AsyncServer(async_mode="asgi", cors_allowed_origins="*", client_manager=mgr)
app = socketio.ASGIApp(sio, app)
@sio.event
async def connect(sid, environ):
print(f"Client connected: {sid}")
await sio.emit("welcome", {"msg": "connected"}, to=sid)
@sio.event
async def ping(sid, data):
print(f"Ping received: {data}")
await sio.emit("pong", {"data": data}, to=sid)
uvicorn test:app --host 0.0.0.0 --port 5000 Fails after the 5 seconds with:
Cannot receive from redis... retrying in 1 secs
With added trace:
Traceback (most recent call last):
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis\asyncio\connection.py", line 541, in read_response
response = await self._parser.read_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis_parsers\resp2.py", line 82, in read_response
response = await self._read_response(disable_decoding=disable_decoding)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis_parsers\resp2.py", line 90, in _read_response
raw = await self._readline()
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis_parsers\base.py", line 219, in _readline
data = await self._stream.readline()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u\AppData\Local\Programs\Python\Python311\Lib\asyncio\streams.py", line 563, in readline
line = await self.readuntil(sep)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u\AppData\Local\Programs\Python\Python311\Lib\asyncio\streams.py", line 655, in readuntil
await self._wait_for_data('readuntil')
File "C:\Users\u\AppData\Local\Programs\Python\Python311\Lib\asyncio\streams.py", line 540, in _wait_for_data
await self._waiter
asyncio.exceptions.CancelledErrorThe above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis\asyncio\connection.py", line 540, in read_response
async with async_timeout(read_timeout):
File "C:\Users\u\AppData\Local\Programs\Python\Python311\Lib\asyncio\timeouts.py", line 115, in aexit
raise TimeoutError from exc_val
TimeoutErrorDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\socketio\async_redis_manager.py", line 110, in _redis_listen_with_retries
async for message in self.pubsub.listen():
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis\asyncio\client.py", line 1035, in listen
response = await self.handle_message(await self.parse_response(block=True))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis\asyncio\client.py", line 922, in parse_response
response = await self._execute(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis\asyncio\client.py", line 902, in _execute
return await conn.retry.call_with_retry(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis\asyncio\retry.py", line 62, in call_with_retry
await fail(error)
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis\asyncio\client.py", line 891, in _disconnect_raise_connect
raise error
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis\asyncio\retry.py", line 59, in call_with_retry
return await do()
^^^^^^^^^^
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis\asyncio\sentinel.py", line 74, in read_response
return await super().read_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u.virtualenvs\proj-FiwSyrnc\Lib\site-packages\redis\asyncio\connection.py", line 559, in read_response
raise TimeoutError(f"Timeout reading from {host_error}")
redis.exceptions.TimeoutError: Timeout reading from h2.net:6379
The redis sentinel connection in isolation works:
from redis.asyncio.sentinel import Sentinel
redis_options={'username': '...', 'password': '...', 'ssl': True, 'sentinel_kwargs': {'ssl': True}, 'socket_timeout': 1, 'db': 0}
sentinel = Sentinel([("h1.net", 26379),("h2", 26379),("h3", 26379)], **redis_options)
print(sentinel.__dict__)
r = sentinel.master_for("mymaster")