Skip to content

Commit 3d7f9f7

Browse files
committed
back to except BaseException
1 parent efa4375 commit 3d7f9f7

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

redis/asyncio/connection.py

Lines changed: 9 additions & 6 deletions
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
768+
# how much data, if any, was successfully sent, so this socket is unusable
769+
# for subsequent commands (which may concatenate to an unfinished command).
767770
await self.disconnect(nowait=True)
768771
raise
769772

@@ -812,11 +815,11 @@ 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
820+
# how much data, if any, was successfully read, so this socket is unusable
821+
# for subsequent commands (which may read previous command's response
822+
# as their own).
820823
await self.disconnect(nowait=True)
821824
raise
822825

redis/connection.py

Lines changed: 9 additions & 2 deletions
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
783+
# how much data, if any, was successfully sent, so this socket is unusable
784+
# for subsequent commands (which may concatenate to an unfinished command).
782785
self.disconnect()
783786
raise
784787

@@ -816,7 +819,11 @@ def read_response(self, disable_decoding=False):
816819
except OSError as e:
817820
self.disconnect()
818821
raise ConnectionError(f"Error while reading from {hosterr}" f" : {e.args}")
819-
except Exception:
822+
except BaseException:
823+
# On interruption (e.g. by gevent.Timeout) there's no way to determine
824+
# how much data, if any, was successfully read, so this socket is unusable
825+
# for subsequent commands (which may read previous command's response
826+
# as their own).
820827
self.disconnect()
821828
raise
822829

0 commit comments

Comments
 (0)