Skip to content

Commit 58390a7

Browse files
committed
more error checking for socket errors
1 parent c2a5026 commit 58390a7

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

redis/connection.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def read(self, length=None):
2323
if length is not None:
2424
return self._fp.read(length+2)[:-2]
2525
return self._fp.readline()[:-2]
26-
except socket.error, e:
26+
except (socket.error, socket.timeout), e:
2727
raise ConnectionError("Error while reading from socket: %s" % \
28-
e.args[1])
28+
(e.args,))
2929

3030
def read_response(self):
3131
response = self.read()
@@ -78,7 +78,11 @@ def on_disconnect(self):
7878
def read_response(self):
7979
response = self._reader.gets()
8080
while response is False:
81-
buffer = self._sock.recv(4096)
81+
try:
82+
buffer = self._sock.recv(4096)
83+
except (socket.error, socket.timeout), e:
84+
raise ConnectionError("Error while reading from socket: %s" % \
85+
(e.args,))
8286
if not buffer:
8387
raise ConnectionError("Socket closed on remote end")
8488
self._reader.feed(buffer)
@@ -264,8 +268,6 @@ def make_connection(self):
264268

265269
def release(self, connection):
266270
"Releases the connection back to the pool"
267-
# assert self._connection == connection
268-
# self._in_use = False
269271
self._in_use_connections.remove(connection)
270272
self._available_connections.append(connection)
271273

0 commit comments

Comments
 (0)