diff options
author | Thomas Jackson <jacksontj.89@gmail.com> | 2014-09-25 16:52:45 -0700 |
---|---|---|
committer | Thomas Jackson <jacksontj.89@gmail.com> | 2014-09-25 18:32:30 -0700 |
commit | 9a6ecbad95cb85487b39102628858df4649a9988 (patch) | |
tree | bb52e0bca1ba7c981c24bc782b860110134b6153 /kazoo/protocol | |
parent | 35f28e0534290fc3df12cc0e927ce10e7eec49f1 (diff) | |
download | kazoo-9a6ecbad95cb85487b39102628858df4649a9988.tar.gz |
Catch interrupted signals (in select) in the threading handler. In addition, use the socket_error_handling context manager in connect loop to raise nicer exceptions
Diffstat (limited to 'kazoo/protocol')
-rw-r--r-- | kazoo/protocol/connection.py | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/kazoo/protocol/connection.py b/kazoo/protocol/connection.py index db1c94c..b07f1be 100644 --- a/kazoo/protocol/connection.py +++ b/kazoo/protocol/connection.py @@ -516,25 +516,26 @@ class ConnectionHandler(object): retry.reset() self._xid = 0 - while not close_connection: - # Watch for something to read or send - jitter_time = random.randint(0, 40) / 100.0 - # Ensure our timeout is positive - timeout = max([read_timeout / 2.0 - jitter_time, jitter_time]) - s = self.handler.select([self._socket, self._read_sock], - [], [], timeout)[0] - - if not s: - if self.ping_outstanding.is_set(): - self.ping_outstanding.clear() - raise ConnectionDropped( - "outstanding heartbeat ping not received") - self._send_ping(connect_timeout) - elif s[0] == self._socket: - response = self._read_socket(read_timeout) - close_connection = response == CLOSE_RESPONSE - else: - self._send_request(read_timeout, connect_timeout) + with self._socket_error_handling(): + while not close_connection: + # Watch for something to read or send + jitter_time = random.randint(0, 40) / 100.0 + # Ensure our timeout is positive + timeout = max([read_timeout / 2.0 - jitter_time, jitter_time]) + s = self.handler.select([self._socket, self._read_sock], + [], [], timeout)[0] + + if not s: + if self.ping_outstanding.is_set(): + self.ping_outstanding.clear() + raise ConnectionDropped( + "outstanding heartbeat ping not received") + self._send_ping(connect_timeout) + elif s[0] == self._socket: + response = self._read_socket(read_timeout) + close_connection = response == CLOSE_RESPONSE + else: + self._send_request(read_timeout, connect_timeout) self.logger.info('Closing connection to %s:%s', host, port) client._session_callback(KeeperState.CLOSED) |