Skip to content

Commit ed977da

Browse files
committed
back to except BaseException
1 parent efa4375 commit ed977da

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

redis/asyncio/connection.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,10 @@ 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+
# On interruption (e.g. by CancelledError) there's no way to determine how much data, if any,
768+
# was successfully sent, so this socket is unusable for subsequent commands (which may concatenate
769+
# to an unfinished command).
767770
await self.disconnect(nowait=True)
768771
raise
769772

@@ -812,11 +815,10 @@ async def read_response(
812815
raise ConnectionError(
813816
f"Error while reading from {self.host}:{self.port} : {e.args}"
814817
)
815-
except asyncio.CancelledError:
816-
# need this check for 3.7, where CancelledError
817-
# is subclass of Exception, not BaseException
818-
raise
819-
except Exception:
818+
except BaseException:
819+
# On interruption (e.g. by CancelledError) there's no way to determine how much data, if any,
820+
# was successfully read, so this socket is unusable for subsequent commands (which may read previous
821+
# command's response as their own).
820822
await self.disconnect(nowait=True)
821823
raise
822824

redis/connection.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,10 @@ 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+
# On interruption (e.g. by gevent Timeout) there's no way to determine how much data, if any,
783+
# was successfully sent, so this socket is unusable for subsequent commands (which may concatenate
784+
# to an unfinished command).
782785
self.disconnect()
783786
raise
784787

@@ -817,6 +820,9 @@ def read_response(self, disable_decoding=False):
817820
self.disconnect()
818821
raise ConnectionError(f"Error while reading from {hosterr}" f" : {e.args}")
819822
except Exception:
823+
# On interruption (e.g. by gevent Timeout) there's no way to determine how much data, if any,
824+
# was successfully read, so this socket is unusable for subsequent commands (which may read previous
825+
# command's response as their own).
820826
self.disconnect()
821827
raise
822828

0 commit comments

Comments
 (0)