summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2018-05-26 08:48:41 -0700
committerGitHub <noreply@github.com>2018-05-26 08:48:41 -0700
commit39ebe1d78b3eee6718aa1cf90547df1f3f38b240 (patch)
treeb4024152f193571abbd21e7ad649eb34f42a9474
parentee26c3f547f357d639b421b3e38a74e87e21f346 (diff)
downloadkafka-python-39ebe1d78b3eee6718aa1cf90547df1f3f38b240.tar.gz
Improve connection handling when bootstrap list is invalid (#1507)
* only perform single dns lookup for connect_blocking() * fix blocking timeout in check_version()
-rw-r--r--kafka/conn.py9
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