You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GeneratorExit error after setting callback on Redis instance from ConnectionPool (Python 3.13, asyncio, redis 7.1.0, Ubuntu #3856
When using Python 3.13 and redis==7.1.0 on Ubuntu 20.04, a Redis instance obtained via ConnectionPool raises a GeneratorExit error after setting a callback.
File "/usr/local/lib/python3.13/site-packages/redis/asyncio/connection.py", line 607, in read_response
response = await self._parser.read_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
disable_decoding=disable_decoding
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
GeneratorExit
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/fit-monitor-web/store/redis_store.py", line 18, in wrapper
return await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/redis/asyncio/client.py", line 725, in execute_command
return await conn.retry.call_with_retry(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<4 lines>...
)
^
File "/usr/local/lib/python3.13/site-packages/redis/asyncio/retry.py", line 50, in call_with_retry
return await do()
^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/redis/asyncio/client.py", line 700, in _send_command_parse_response
return await self.parse_response(conn, command_name, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/redis/asyncio/client.py", line 746, in parse_response
response = await connection.read_response()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/redis/asyncio/connection.py", line 627, in read_response
await self.disconnect(nowait=True)
File "/usr/local/lib/python3.13/site-packages/redis/asyncio/connection.py", line 482, in disconnect
async with async_timeout(self.socket_connect_timeout):
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/asyncio/timeouts.py", line 90, in __aenter__
raise RuntimeError("Timeout should be used inside a task")
RuntimeError: Timeout should be used inside a task
Hi @MM-X-C, thanks for bringing this up! Can you please add a small code example that reproduces the issue?
When I place the callback method in a class and register it via a class method or instance method, the GeneratorExit error occurs within a few minutes of service startup. When I set the callback as a function instead, it hasn't reproduced yet so far—the situation seems improved, but I'm not sure if it will happen again. I don't know why this is the case.
from redis import asyncio as aioredis
class RedisConnection:
def __init__(self, host, port, decode_responses=True, db=0, pwd=None, **kwargs):
self.pool = aioredis.ConnectionPool.from_url(
f"redis://{host}:{port}/{db}",
password=pwd,
decode_responses=decode_responses,
socket_connect_timeout=1,
retry_on_timeout=True,
)
self.r = aioredis.Redis(connection_pool=self.pool)
if 'response_callbacks' in kwargs:
for command, callback_func in kwargs['response_callbacks'].items():
if hasattr(self, callback_func):
self.r.set_response_callback(command, getattr(self, callback_func))
else:
logger.error(f"No callback for {command}")
Hi @MM-X-C, thanks for bringing this up! Can you please add a small code example that reproduces the issue?
When I place the callback method in a class and register it via a class method or instance method, the GeneratorExit error occurs within a few minutes of service startup. When I set the callback as a function instead, it hasn't reproduced yet so far—the situation seems improved, but I'm not sure if it will happen again. I don't know why this is the case.
from redis import asyncio as aioredis
class RedisConnection:
def __init__(self, host, port, decode_responses=True, db=0, pwd=None, **kwargs):
self.pool = aioredis.ConnectionPool.from_url(
f"redis://{host}:{port}/{db}",
password=pwd,
decode_responses=decode_responses,
socket_connect_timeout=1,
retry_on_timeout=True,
)
self.r = aioredis.Redis(connection_pool=self.pool)
if 'response_callbacks' in kwargs:
for command, callback_func in kwargs['response_callbacks'].items():
if hasattr(self, callback_func):
self.r.set_response_callback(command, getattr(self, callback_func))
else:
logger.error(f"No callback for {command}")
It turns out that this issue is unrelated to class instances or class methods; callbacks set on standalone functions can also trigger the same problem. After implementing function-level callbacks, it reproduced today.
Activity
petyaslavova commentedon Nov 26, 2025
Hi @MM-X-C, thanks for bringing this up! Can you please add a small code example that reproduces the issue?
MM-X-C commentedon Nov 27, 2025
When I place the callback method in a class and register it via a class method or instance method, the GeneratorExit error occurs within a few minutes of service startup. When I set the callback as a function instead, it hasn't reproduced yet so far—the situation seems improved, but I'm not sure if it will happen again. I don't know why this is the case.
MM-X-C commentedon Nov 28, 2025
It turns out that this issue is unrelated to class instances or class methods; callbacks set on standalone functions can also trigger the same problem. After implementing function-level callbacks, it reproduced today.
fix: guard disconnect() against RuntimeError on Python 3.13+ (#3856)
fix: guard disconnect() against RuntimeError on Python 3.13+ (#3856) (#…