Skip to content

fix(redis-streams): use blocking connection pool for redis-py 8 compatibility#223

Open
pcanto-hopeit wants to merge 2 commits into
hopeit-git:masterfrom
pcanto-hopeit:fix/redis-streams-blocking-pool
Open

fix(redis-streams): use blocking connection pool for redis-py 8 compatibility#223
pcanto-hopeit wants to merge 2 commits into
hopeit-git:masterfrom
pcanto-hopeit:fix/redis-streams-blocking-pool

Conversation

@pcanto-hopeit

Copy link
Copy Markdown
Collaborator

This PR updates hopeit.redis_streams.RedisStreamManager to use redis.asyncio.connection.BlockingConnectionPool instead of the default async Redis connection pool.

It also exposes Redis stream pool settings through StreamsConfig:

  • max_connections, default 100
  • blocking_pool_timeout, default 20.0
  • protocol, default 2

Problem

With redis==7.4.1, the default async ConnectionPool effectively allowed a very high number of connections.

With redis==8.0.0, the default changed to 100. Since the regular pool raises immediately when exhausted, concurrent Redis Stream writes can fail with:

redis.exceptions.MaxConnectionsError: Too many connections

This can happen when Hopeit publishes an event result or downstream event through write_stream(...), specifically during XADD.

Fix

Fixes #222

RedisStreamManager now creates separate read and write Redis clients backed by BlockingConnectionPool.

When the pool reaches max_connections, concurrent operations wait up to blocking_pool_timeout for an available connection instead of failing immediately.

The Redis client shutdown path was also updated to use aclose(close_connection_pool=True) when available, with a fallback to close().

Tests

Added unit coverage for:

  • Redis stream client creation using BlockingConnectionPool
  • passing max_connections, blocking_pool_timeout, and protocol
  • concurrent write_stream(...) calls with low max_connections
  • closing read/write clients cleanly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(redis-streams): MaxConnectionsError when writing streams with redis-py 8

1 participant