diff options
author | Dana Powers <dana.powers@gmail.com> | 2018-05-25 00:06:02 -0700 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2018-05-25 00:06:02 -0700 |
commit | b46ff753bb3c08124da84702dea4f9bcebb3ab63 (patch) | |
tree | 0d47e052383f777913d17eed0e957956e7114abc /kafka | |
parent | c9d783a8211337205bc90c27d1f67beb65ac5d9e (diff) | |
download | kafka-python-connect_blocking_fixups.tar.gz |
Only perform single dns lookup for connect_blocking; fix blocking timeout in check_versionconnect_blocking_fixups
Diffstat (limited to 'kafka')
-rw-r--r-- | kafka/conn.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/kafka/conn.py b/kafka/conn.py index f67edfb..a2d5ee6 100644 --- a/kafka/conn.py +++ b/kafka/conn.py @@ -292,11 +292,7 @@ class BrokerConnection(object): # First attempt to perform dns lookup # note that the underlying interface, socket.getaddrinfo, # has no explicit timeout so we may exceed the user-specified timeout - while time.time() < timeout: - if self._dns_lookup(): - break - else: - return False + self._dns_lookup() # Loop once over all returned dns entries selector = None @@ -903,6 +899,7 @@ class BrokerConnection(object): Returns: version tuple, i.e. (0, 10), (0, 9), (0, 8, 2), ... """ + timeout_at = time.time() + timeout log.info('Probing node %s broker version', self.node_id) # Monkeypatch some connection configurations to avoid timeouts override_config = { @@ -932,7 +929,7 @@ class BrokerConnection(object): ] for version, request in test_cases: - if not self.connect_blocking(timeout): + if not self.connect_blocking(timeout_at - time.time()): raise Errors.NodeNotReadyError() f = self.send(request) # HACK: sleeping to wait for socket to send bytes |