diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2014-04-29 12:48:44 -0700 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2014-04-29 12:48:44 -0700 |
commit | 6eeb4ee148516de1b3e1f449e26b16457a874a57 (patch) | |
tree | bd8b9967ac21cc8cddd67a62ec0c95eae8fda946 /redis/connection.py | |
parent | 1851035084f49c483d74b41ffc79a50d019e97c5 (diff) | |
download | redis-py-6eeb4ee148516de1b3e1f449e26b16457a874a57.tar.gz |
receiving empty strings from socket.recv indicates the server hungup.
fixes #386 and #465. Thanks David Lawrence.
Diffstat (limited to 'redis/connection.py')
-rw-r--r-- | redis/connection.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/redis/connection.py b/redis/connection.py index 3364364..d6a2931 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -80,6 +80,9 @@ class SocketBuffer(object): try: while True: data = self._sock.recv(socket_read_size) + # an empty string indicates the server shutdown the socket + if isinstance(data, str) and len(data) == 0: + raise socket.error("Connection closed by remote server.") buf.write(data) data_length = len(data) self.bytes_written += data_length @@ -281,6 +284,9 @@ class HiredisParser(BaseParser): while response is False: try: buffer = self._sock.recv(socket_read_size) + # an empty string indicates the server shutdown the socket + if isinstance(buffer, str) and len(buffer) == 0: + raise socket.error("Connection closed by remote server.") except (socket.error, socket.timeout): e = sys.exc_info()[1] raise ConnectionError("Error while reading from socket: %s" % |