diff options
-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 |