7

Preconditions:

python 3.8
aioredis==1.3.0

Sometimes errors below appear in production in sentry:

Task was destroyed but it is pending!
task: <Task pending name='Task-16349' coro=<RedisConnection._read_data() running at /usr/local/lib/python3.8/site-packages/aioredis/connection.py:183> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x2ac9dc15e430>()]> cb=[RedisConnection.__init__.<locals>.<lambda>() at /usr/local/lib/python3.8/site-packages/aioredis/connection.py:165]>

Has anyone come across this? Рow did you fix it?

Some additional information. We use aiohttp==3.7.3. Part of my Redis client:

class RedisClient:
    redis: Optional[aioredis.Redis] = None
    encoding: str = 'utf-8'

    @classmethod
    async def create_redis_pool(cls):
        if cls.redis is None:
            redis_address = 'redis://%s:%d' % (settings.REDIS['host'], settings.REDIS['port'])
            cls.redis = await aioredis.create_redis_pool(
                redis_address,
                db=settings.REDIS['db'],
                minsize=settings.REDIS['minsize'],
                maxsize=settings.REDIS['maxsize'],
                timeout=10
            )
        return cls.redis

    ...

    @classmethod
    async def get(cls, key, encoding=encoding):
        return await cls.redis.get(key, encoding=encoding)

A pool of connections to redis is created at the start of the application.

  • 1
    You can [edit](https://stackoverflow.com/help/how-to-ask) your question and add the additional information that you have posted in the below answer section. – Girish Feb 16 '21 at 12:10
  • I use aioredis in a task created by asyncio.create_task and came across the same problem – Tom Chen Jul 20 '21 at 14:05

0 Answers0