diff options
author | Dana Powers <dana.powers@gmail.com> | 2016-04-07 21:53:52 -0700 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2016-04-07 22:54:08 -0700 |
commit | 2f1aee387e25d7466df3518f7ec73d0649145462 (patch) | |
tree | aa30c392f62dd372f026097f7f7517acfb8db511 | |
parent | ee21f095f95f8c8bde06203215bd6096f1944430 (diff) | |
download | kafka-python-2f1aee387e25d7466df3518f7ec73d0649145462.tar.gz |
Raise ConnectionError immediately on disconnect in SimpleClient._get_conn
-rw-r--r-- | kafka/client.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/kafka/client.py b/kafka/client.py index 6a1a63b..891ae03 100644 --- a/kafka/client.py +++ b/kafka/client.py @@ -67,11 +67,18 @@ class SimpleClient(object): ) conn = self._conns[host_key] + conn.connect() + if conn.connected(): + return conn + timeout = time.time() + self.timeout - while time.time() < timeout: + while time.time() < timeout and conn.connecting(): if conn.connect() is ConnectionStates.CONNECTED: break + else: + time.sleep(0.05) else: + conn.close() raise ConnectionError("%s:%s (%s)" % (host, port, afi)) return conn |