summaryrefslogtreecommitdiff
path: root/redis/connection.py
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2014-04-29 12:48:44 -0700
committerAndy McCurdy <andy@andymccurdy.com>2014-04-29 12:48:44 -0700
commit6eeb4ee148516de1b3e1f449e26b16457a874a57 (patch)
treebd8b9967ac21cc8cddd67a62ec0c95eae8fda946 /redis/connection.py
parent1851035084f49c483d74b41ffc79a50d019e97c5 (diff)
downloadredis-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.py6
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" %