-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix ConnectionPool to raise MaxConnectionsError instead of Connection… #3698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix ConnectionPool to raise MaxConnectionsError instead of Connection… #3698
Conversation
…Error - Added MaxConnectionsError class as a subclass of ConnectionError - Updated connection.py to raise the more specific error - Updated cluster.py to handle this specific error type - Added tests to verify the behavior Fixes redis#3684
993234b
to
229f857
Compare
Removed unnecessary methods and attributes from the DummyConnection class that were introduced during development. This restores the class to its minimal implementation needed for testing the MaxConnectionsError behavior.
Removed extra whitespace in the DummyConnection class in test_connection_pool.py to maintain consistent indentation throughout the file. This helps maintain code style consistency across the codebase.
Hi @ngabhanenetskope, thank you for the time and effort you've put into this PR! Can you please also update the async cluster client to have the same behavior? |
Add explanatory comment to the exception handling for MaxConnectionsError in the async cluster implementation, matching the synchronous version. This ensures consistent behavior between sync and async implementations when connection pool is exhausted, preventing unnecessary cluster reinitialization.
Thank you for the review! I've updated the async cluster implementation to handle MaxConnectionsError consistently with the synchronous version. The good news is that the async cluster code was already catching MaxConnectionsError and preventing cluster reinitialization, but I've:
This ensures that both sync and async cluster implementations have consistent behavior when the connection pool is exhausted. |
@ngabhanenetskope, please check the linters errors. |
- Fix import order in cluster.py to resolve I001 linting error - Remove trailing whitespace in MaxConnectionsError class in exceptions.py - Fix whitespace issues in test_max_connections_error.py
I've just fixed the linter errors in my PR. The changes include:
All these changes are now committed to the PR branch. The tests continue to pass successfully. |
- Format code with ruff to comply with style guidelines - Fix line length issues - Change single quotes to double quotes - Add proper spacing between methods for better readability
@petyaslavova |
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.