diff options
author | andy <andy@whiskeymedia.com> | 2011-07-22 16:23:34 -0700 |
---|---|---|
committer | andy <andy@whiskeymedia.com> | 2011-07-22 16:23:34 -0700 |
commit | 79d22358410936358c71c88abbdb2a26e3cedc28 (patch) | |
tree | 36ae1cb6b23e9a05833ebf8073a93996ef152e30 /redis/connection.py | |
parent | dbd2217746eeb81950e91c556bb393e95aca5582 (diff) | |
download | redis-py-79d22358410936358c71c88abbdb2a26e3cedc28.tar.gz |
Ensure connections get disconnected if there's a protocol error
Diffstat (limited to 'redis/connection.py')
-rw-r--r-- | redis/connection.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/redis/connection.py b/redis/connection.py index a85129b..79f767e 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -181,14 +181,16 @@ class Connection(object): try: self._sock.sendall(command) except socket.error, e: - if e.args[0] == errno.EPIPE: - self.disconnect() + self.disconnect() if len(e.args) == 1: _errno, errmsg = 'UNKNOWN', e.args[0] else: _errno, errmsg = e.args raise ConnectionError("Error %s while writing to socket. %s." % \ (_errno, errmsg)) + except: + self.disconnect() + raise def send_command(self, *args): "Pack and send a command to the Redis server" @@ -196,7 +198,11 @@ class Connection(object): def read_response(self): "Read the response from a previously sent command" - response = self._parser.read_response() + try: + response = self._parser.read_response() + except: + self.disconnect() + raise if response.__class__ == ResponseError: raise response return response |