fix(redis-streams): use blocking connection pool for redis-py 8 compatibility#223
Open
pcanto-hopeit wants to merge 2 commits into
Open
fix(redis-streams): use blocking connection pool for redis-py 8 compatibility#223pcanto-hopeit wants to merge 2 commits into
pcanto-hopeit wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR updates
hopeit.redis_streams.RedisStreamManagerto useredis.asyncio.connection.BlockingConnectionPoolinstead of the default async Redis connection pool.It also exposes Redis stream pool settings through
StreamsConfig:max_connections, default100blocking_pool_timeout, default20.0protocol, default2Problem
With
redis==7.4.1, the default asyncConnectionPooleffectively allowed a very high number of connections.With
redis==8.0.0, the default changed to100. Since the regular pool raises immediately when exhausted, concurrent Redis Stream writes can fail with:redis.exceptions.MaxConnectionsError: Too many connectionsThis can happen when Hopeit publishes an event result or downstream event through
write_stream(...), specifically duringXADD.Fix
Fixes #222
RedisStreamManagernow creates separate read and write Redis clients backed byBlockingConnectionPool.When the pool reaches
max_connections, concurrent operations wait up toblocking_pool_timeoutfor 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 toclose().Tests
Added unit coverage for:
BlockingConnectionPoolmax_connections,blocking_pool_timeout, andprotocolwrite_stream(...)calls with lowmax_connections