Fix ConnectionPool to raise MaxConnectionsError instead of Connection… #3698
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.
Pull Request check-list
Please make sure to review and check all of these items:
Description of change
This PR addresses issue #3684 by introducing a more specific
MaxConnectionsError
exception that is raised when a connection pool reaches its maximum connections limit.Current behavior:
When a
ConnectionPool
reaches its maximum connections limit, it raises a genericConnectionError
. This causesRedisCluster
to treat the error as a node failure and trigger an unnecessary cluster reinitialization, leading to increased resource usage.Changes:
MaxConnectionsError
class inredis/exceptions.py
as a subclass ofConnectionError
ConnectionPool.make_connection()
inredis/connection.py
to raise the newMaxConnectionsError
instead of a genericConnectionError
RedisCluster._execute_command()
inredis/cluster.py
to handleMaxConnectionsError
separately, preventing unnecessary cluster reinitialization__init__.py
to make the new exception availableTesting:
test_max_connections
intest_connection_pool.py
to expectMaxConnectionsError
test_max_connections_error.py
with:MaxConnectionsError
extendsConnectionError
MaxConnectionsError
All tests pass locally, including the new tests specifically for this behavior.
Note: The issue was previously assigned but appears to be inactive. I implemented this fix because it was affecting our production environment.