Skip to content

RuntimeError: list changed size during iteration on asyncio PubSub get_message #3748

@ac3673

Description

@ac3673

Environment
redis-py 6.2.0 (also happened on 6.4)
python 3.12
default parser (no hiredis)

retry = Retry(ExponentialBackoff(), 3)
client: Redis = redis.from_url(
    url
    retry=retry, 
    decode_responses=True)
pubsub: PubSub = client.pubsub()
await pubsub.subscribe(channel_1)
await pubsub.subscribe(channel_2)
while True:
    message = await pubsub.get_message(ignore_subscribe_messages=True, timeout=0.01)

Getting stack trace. Happens intermittently. I tried adjusting the timeout if it mattered but still got the error.

    message = await pubsub.get_message(ignore_subscribe_messages=True, timeout=0.01)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srvc_wftcproject/apps/frontier-acm/.venv/lib/python3.12/site-packages/redis/asyncio/client.py", line 1111, in get_message
    response = await self.parse_response(block=(timeout is None), timeout=timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srvc_wftcproject/apps/frontier-acm/.venv/lib/python3.12/site-packages/redis/asyncio/client.py", line 984, in parse_response
    response = await self._execute(
               ^^^^^^^^^^^^^^^^^^^^
  File "/home/srvc_wftcproject/apps/frontier-acm/.venv/lib/python3.12/site-packages/redis/asyncio/client.py", line 964, in _execute
    return await conn.retry.call_with_retry(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srvc_wftcproject/apps/frontier-acm/.venv/lib/python3.12/site-packages/redis/asyncio/retry.py", line 71, in call_with_retry
    return await do()
           ^^^^^^^^^^
  File "/home/srvc_wftcproject/apps/frontier-acm/.venv/lib/python3.12/site-packages/redis/asyncio/connection.py", line 585, in read_response
    async with async_timeout(read_timeout):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srvc_wftcproject/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/asyncio/timeouts.py", line 94, in __aenter__
    self.reschedule(self._when)
  File "/home/srvc_wftcproject/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/asyncio/timeouts.py", line 71, in reschedule
    self._timeout_handler = loop.call_at(when, self._on_timeout)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srvc_wftcproject/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/asyncio/base_events.py", line 781, in call_at
    heapq.heappush(self._scheduled, timer)
RuntimeError: list changed size during iteration

Metadata

Metadata

Assignees

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