CRE-2025-0041
redis-py client fails with AttributeError when reused across async or process contextsLowImpact: 5/10Mitigation: 4/10
CRE-2025-0041View on GitHub
Description
- In redis-py v5.x, sharing a single Redis client across async tasks or subprocesses can result in:
- `AttributeError: ''NoneType'' object has no attribute ''getpid''`.
- This typically occurs when the client or connection pool is reused across forks or when event loop context is lost, especially in async frameworks or multiprocessing setups.
Cause
redis-py tracks the active event loop and process ID in the connection pool. If a Redis client is reused in a different process or async task after the original event loop is gone, internal context like `self._loop` becomes `None`, causing `self._loop.getpid()` to raise an AttributeError.
Mitigation
- Avoid sharing Redis clients across processes or async task groups.
- Recreate clients inside subprocesses or use context-aware pools.
- Use `redis.asyncio.ConnectionPool` directly if managing multiple workers manually.
- Upgrade to the patched version of redis-py (see PR #3015).