Skip to content

Connection pool throws error instead of blocking until connection is available: redis.exceptions.ConnectionError: Too many connections #2517

@Fogapod

Description

@Fogapod

Version: 4.4.0
Platform: Linux
Description: Connection pool works in unexpected way: when connection limit is reached it throws an error.

Code to reproduce:

import asyncio

from redis import asyncio as redis


async def main() -> None:
    async with redis.Redis(max_connections=2) as rd:
        await asyncio.gather(*[rd.set(str(i), i) for i in range(100)])


asyncio.run(main())

By default redis sets connection limit to ridiculously high number: #2220
This hides the issue with pool. When set so something realistic like 50 or 100 it starts throwing redis.exceptions.ConnectionError: Too many connections under load.

This bug was introduced in aioredis 2.0, here is relevant issue in aioredis repo: aio-libs-abandoned/aioredis-py#1173
This comment in particular explains the problem: aio-libs-abandoned/aioredis-py#1173 (comment)

aredis has the same design for some reason: NoneGG/aredis#167
Other than that I am unfamiliar with async connection pool implementations that would throw errors instead of waiting so I think this is a bug.

I think sync pool works in the same way. Probably not a desired behaviour for sync apps as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions