-
Notifications
You must be signed in to change notification settings - Fork 0
[GROW-3247] release connection even if an unexpected exception is thrown in cluster pipeline #8
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
Conversation
…own in cluster pipeline
*c.args, node_flag=passed_targets | ||
) | ||
if not target_nodes: | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff is mostly due to the added indentation. the only code i've added are try
, except BaseException
, n.connection = None
and nodes = {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG never knew about this...
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #8 +/- ##
==========================================
- Coverage 92.34% 92.33% -0.02%
==========================================
Files 119 119
Lines 30615 30638 +23
==========================================
+ Hits 28272 28289 +17
- Misses 2343 2349 +6
☔ View full report in Codecov by Sentry. |
n.connection = None | ||
nodes = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added n.connection = None
, so that already returned n.connection is not used again
added nodes = {}
to clear out NodeCommands from nodes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unassignement is similar to the below code
https://github.com/redis/redis-py/blob/2732a8553e58d9e77f16566b9132fc7205614a53/redis/client.py#L1181-L1183
n.connection = None | ||
nodes = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added n.connection = None
, so that already returned n.connection is not used again
added nodes = {}
to clear out NodeCommands from nodes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unassignement is similar to the below code
https://github.com/redis/redis-py/blob/2732a8553e58d9e77f16566b9132fc7205614a53/redis/client.py#L1181-L1183
except BaseException: | ||
# if nodes is not empty, a problem must have occurred | ||
# since we cant guarantee the state of the connections, | ||
# disconnect before returning it to the connection pool | ||
for n in nodes.values(): | ||
if n.connection: | ||
n.connection.disconnect() | ||
n.connection_pool.release(n.connection) | ||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've added this to disconnect and return the connection to the pool
for n in nodes.values(): | ||
n.connection_pool.release(n.connection) | ||
n.connection = None | ||
nodes = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodes = {} | |
del nodes[node_name] |
I don't think we should delete other healthy nodes. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the variable name is confusing, but nodes
here aren't actual nodes in the redis cluster, but NodeCommands object that's only used in this function. Since we raise the exception in line 2051 anyway, there is no difference between del nodes[node_name]
vs nodes = {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for me, it completely makes sense. But beside of the changes of this PR, I can't see any reason to have infinite loop in here, because there is no continue
or other paths to reach to break
line except some exceptions that percolate up to out of loop (and loop is useless for this exception cases)
*c.args, node_flag=passed_targets | ||
) | ||
if not target_nodes: | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i completely agree. It was introduced in https://github.com/redis/redis-py/pull/2225/files, but i think continue statement got lost afterwards |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!!!
…own in cluster pipeline (#8) * [GROW-3247] release connection even if an unexpected exception is thrown in cluster pipeline * [GROW-3247] fix style issue * unassign n.connection at every loop
…own in cluster pipeline (#8) * [GROW-3247] release connection even if an unexpected exception is thrown in cluster pipeline * [GROW-3247] fix style issue * unassign n.connection at every loop
…own in cluster pipeline (#8) * [GROW-3247] release connection even if an unexpected exception is thrown in cluster pipeline * [GROW-3247] fix style issue * unassign n.connection at every loop
…own in cluster pipeline (#8) * [GROW-3247] release connection even if an unexpected exception is thrown in cluster pipeline * [GROW-3247] fix style issue * unassign n.connection at every loop
…own in cluster pipeline (#8) * [GROW-3247] release connection even if an unexpected exception is thrown in cluster pipeline * [GROW-3247] fix style issue * unassign n.connection at every loop
Pull Request check-list
Please make sure to review and check all of these items:
$ tox
pass with this change (including linting)?NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Description of change
i've confirmed that the connection is not released to the connection pool, when an unexpected exception occurs during cluster pipeline execution. This PR ensures that ClusterPipeline releases connection, even if an unexpected exception occurs.
connections are disconnected before they are released to the pool in order to prevent any socket-related issues that redis-py comment discusses