Skip to content

Commit

Permalink
Issue #37: Handle timeout errors during select calls on sockets.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Nov 2, 2012
1 parent b587043 commit dee970c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -9,6 +9,8 @@ Bug Handling

- Issue #38: Set `CLOEXEC` flag on all sockets when available.

- Issue #37: Handle timeout errors during `select` calls on sockets.

0.8 (2012-10-26)
----------------

Expand Down
14 changes: 12 additions & 2 deletions kazoo/protocol/connection.py
Expand Up @@ -165,7 +165,12 @@ def _read(self, length, timeout):
with socket_error_handling():
while remaining > 0:
s = self.handler.select([self._socket], [], [], timeout)[0]
chunk = s[0].recv(remaining)
try:
chunk = s[0].recv(remaining)
except IndexError: # pragma: nocover
# If the read list is empty, we got a timeout. We don't
# have to check wlist and xlist as we don't set any
raise self.handler.timeout_exception("socket time-out")
if chunk == b'':
raise ConnectionDropped('socket connection broken')
msgparts.append(chunk)
Expand Down Expand Up @@ -229,7 +234,12 @@ def _write(self, msg, timeout):
while sent < msg_length:
s = self.handler.select([], [self._socket], [], timeout)[1]
msg_slice = buffer(msg, sent)
bytes_sent = s[0].send(msg_slice)
try:
bytes_sent = s[0].send(msg_slice)
except IndexError: # pragma: nocover
# If the write list is empty, we got a timeout. We don't
# have to check rlist and xlist as we don't set any
raise self.handler.timeout_exception("socket time-out")
if not bytes_sent:
raise ConnectionDropped('socket connection broken')
sent += bytes_sent
Expand Down

0 comments on commit dee970c

Please sign in to comment.