Skip to content

Commit 1985884

Browse files
committed
Close a Connection whenever an exception is raised for send_command()
The api does not allow for a "resume", e.g. on a timeout, because an unknown number of bytes has been sent and an internal send state is not maintained. Therefore, there is no point in keeping the connection open.
1 parent c3d8a7c commit 1985884

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

redis/asyncio/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,11 @@ async def send_packed_command(
763763
raise ConnectionError(
764764
f"Error {err_no} while writing to socket. {errmsg}."
765765
) from e
766-
except Exception:
766+
except BaseException:
767+
# The send_packed_command api does not support re-trying a partially
768+
# sent message, so there is no point in keeping the connection open.
769+
# An unknown number of bytes has been sent and the connection is therefore
770+
# unusable.
767771
await self.disconnect(nowait=True)
768772
raise
769773

redis/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,11 @@ def send_packed_command(self, command, check_health=True):
778778
errno = e.args[0]
779779
errmsg = e.args[1]
780780
raise ConnectionError(f"Error {errno} while writing to socket. {errmsg}.")
781-
except Exception:
781+
except BaseException:
782+
# The send_packed_command api does not support re-trying a partially
783+
# sent message, so there is no point in keeping the connection open.
784+
# An unknown number of bytes has been sent and the connection is therefore
785+
# unusable.
782786
self.disconnect()
783787
raise
784788

0 commit comments

Comments
 (0)