Skip to content

RuntimeError: readuntil() called while another coroutine is already waiting for incoming data #2540

Closed
@Tiendil

Description

@Tiendil

Version: redis==4.4.0, Redis: redis:6.2-alpine (docker)

Platform: Python 3.9.16, docker python:3.9

Description: Redis client raises RuntimeError while doing multiple concurrency operations.

Reproduced on 4.4.0, ok on 4.3.5

Example code:

import asyncio
import uuid

from redis.asyncio import Redis


async def main():

    client = Redis(
        host="redis",
        port=6379,
        db=0,
        username=None,
        password=None,
        retry_on_timeout=True,
        single_connection_client=True,
        client_name='test_client',
    )

    # At my PC stable reproduces with n=10, but let set n=100 for better guarantees
    n = 100

    async def problem():
        await client.delete(uuid.uuid4().hex)
        await client.delete(uuid.uuid4().hex)  # <- problem is at this line

    operations = [problem() for i in range(n)]

    await asyncio.gather(*operations)

    print('success!')

Stacktrace:

Traceback (most recent call last):
  File "/app/x.py", line 36, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/app/x.py", line 33, in main
    await asyncio.gather(*operations)
  File "/app/x.py", line 29, in problem
    await client.delete(uuid.uuid4().hex)  # <- problem is at this line
  File "/tmp/venv/lib/python3.9/site-packages/redis/asyncio/client.py", line 505, in execute_command
    return await conn.retry.call_with_retry(
  File "/tmp/venv/lib/python3.9/site-packages/redis/asyncio/retry.py", line 59, in call_with_retry
    return await do()
  File "/tmp/venv/lib/python3.9/site-packages/redis/asyncio/client.py", line 481, in _send_command_parse_response
    return await self.parse_response(conn, command_name, **options)
  File "/tmp/venv/lib/python3.9/site-packages/redis/asyncio/client.py", line 524, in parse_response
    response = await connection.read_response()
  File "/tmp/venv/lib/python3.9/site-packages/redis/asyncio/connection.py", line 800, in read_response
    response = await self._parser.read_response(
  File "/tmp/venv/lib/python3.9/site-packages/redis/asyncio/connection.py", line 245, in read_response
    raw = await self._readline()
  File "/tmp/venv/lib/python3.9/site-packages/redis/asyncio/connection.py", line 311, in _readline
    data = await self._stream.readline()
  File "/usr/local/lib/python3.9/asyncio/streams.py", line 540, in readline
    line = await self.readuntil(sep)
  File "/usr/local/lib/python3.9/asyncio/streams.py", line 632, in readuntil
    await self._wait_for_data('readuntil')
  File "/usr/local/lib/python3.9/asyncio/streams.py", line 503, in _wait_for_data
    raise RuntimeError(
RuntimeError: readuntil() called while another coroutine is already waiting for incoming data

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions