For my python (python 3.10)
based project, we were using aioredis (aioredis 2.0.1)
to connect to redis cache and all of a sudden all the requests accessing redis cache started failing. After analysis, we found that Aioredis is now in redis-py. Post that we removed aioredis and added redis (redis 4.5.1)
as a dependency in pipfile.
I didn't added any extra code just changed the imports from
import aioredis
to
from redis import asyncio as aioredis
But that didn't resolve the issue completely, now half of the requests are failing with the error code as below.(In an hour 145 requests were success while 79 failed)
redis.exceptions.ConnectionError: Error UNKNOWN while writing to socket. Connection lost
we use aioredis.Redis for connection
aioredis.Redis(
host=redis_hostname,
port=redis_port,
db=db_name,
password=redis_password,
ssl=true,
connection_pool=aioredis.ConnectionPool.from_url(
f"{redis_protocol}://:{redis_password}@{redis_hostname}:{redis_port}/{db_name}",
connection_class=aioredis.Connection,
max_connections=redis_pool_size,
)
Below is the error trace
Traceback (most recent call last): File /usr/local/lib/python3.10/site-packages/redis/asyncio/connection.py, line 788, in send_packed_command await self._writer.drain()
File /usr/local/lib/python3.10/asyncio/streams.py, line 371, in drain await self._protocol._drain_helper()
Traceback (most recent call last): File /usr/local/lib/python3.10/site-packages/ddtrace/contrib/asgi/middleware.py, line 173, in call return await self.app(scope, receive, wrapped_send)
File /usr/local/lib/python3.10/asyncio/streams.py, line 167, in _drain_helper raise ConnectionResetError('Connection lost')ConnectionResetError: Connection lost The above exception was the direct cause of the following exception:
.....
File /usr/local/lib/python3.10/site-packages/redis/asyncio/client.py, line 487, in _send_command_parse_response await conn.send_command(*args)redis.exceptions.ConnectionError: Error UNKNOWN while writing to socket. Connection lost.