From 83013b5df1ea32213a77f81be08ffb40d56bace6 Mon Sep 17 00:00:00 2001 From: Andy McCurdy Date: Sun, 6 Jul 2014 19:52:28 -0700 Subject: [PATCH] check for the server closing a connection that's compatible with Python 3 fixes #508 --- CHANGES | 2 ++ redis/connection.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 15f66f7d71..d1c021d695 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,8 @@ either to StrictRedis.__init__ or from_url will still work but will also emit a DeprecationWarning. Instead use the "encoding" and "encoding_errors" options. + * Fixed a compatability bug with Python 3 when sockets the server closes + a connection. * 2.10.1 * Fixed a bug where Sentinel connections to a server that's no longer a master and receives a READONLY error will disconnect and reconnect to diff --git a/redis/connection.py b/redis/connection.py index 4c142334db..e39bd392cc 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -108,7 +108,7 @@ def _read_from_socket(self, length=None): 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: + if isinstance(data, bytes) and len(data) == 0: raise socket.error("Connection closed by remote server.") buf.write(data) data_length = len(data) @@ -314,7 +314,7 @@ def read_response(self): 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: + if isinstance(buffer, bytes) and len(buffer) == 0: raise socket.error("Connection closed by remote server.") except socket.timeout: raise TimeoutError("Timeout reading from socket")