Skip to content

Commit

Permalink
back to except BaseException
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst committed Dec 11, 2022
1 parent efa4375 commit 3d7f9f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
15 changes: 9 additions & 6 deletions redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,10 @@ async def send_packed_command(
raise ConnectionError(
f"Error {err_no} while writing to socket. {errmsg}."
) from e
except Exception:
except BaseException:
# On interruption (e.g. by CancelledError) there's no way to determine
# how much data, if any, was successfully sent, so this socket is unusable
# for subsequent commands (which may concatenate to an unfinished command).
await self.disconnect(nowait=True)
raise

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

Expand Down
11 changes: 9 additions & 2 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,10 @@ 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:
# On interruption (e.g. by gevent.Timeout) there's no way to determine
# how much data, if any, was successfully sent, so this socket is unusable
# for subsequent commands (which may concatenate to an unfinished command).
self.disconnect()
raise

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

Expand Down

0 comments on commit 3d7f9f7

Please sign in to comment.