From e86b6d21bea284097398076e059f62eb53a896ca Mon Sep 17 00:00:00 2001 From: Dana Powers Date: Thu, 7 Apr 2016 21:53:52 -0700 Subject: Raise ConnectionError immediately on disconnect in SimpleClient._get_conn --- kafka/client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1