Skip to content
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

Close a Connection whenever an exception is raised for send_command() #2516

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Close Connection on all send_command() errors (#2516)
* Documentation fix: password protected socket connection (#2374)
* Allow `timeout=None` in `PubSub.get_message()` to wait forever
* add `nowait` flag to `asyncio.Connection.disconnect()`
Expand Down
6 changes: 5 additions & 1 deletion redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,11 @@ async def send_packed_command(
raise ConnectionError(
f"Error {err_no} while writing to socket. {errmsg}."
) from e
except Exception:
except BaseException:
# The send_packed_command api does not support re-trying a partially
# sent message, so there is no point in keeping the connection open.
# An unknown number of bytes has been sent and the connection is therefore
# unusable.
await self.disconnect(nowait=True)
raise

Expand Down
6 changes: 5 additions & 1 deletion redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,11 @@ def send_packed_command(self, command, check_health=True):
errno = e.args[0]
errmsg = e.args[1]
raise ConnectionError(f"Error {errno} while writing to socket. {errmsg}.")
except Exception:
except BaseException:
# The send_packed_command api does not support re-trying a partially
# sent message, so there is no point in keeping the connection open.
# An unknown number of bytes has been sent and the connection is therefore
# unusable.
self.disconnect()
raise

Expand Down