Skip to content

Improve connection handling when bootstrap list is invalid #1507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions kafka/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,7 @@ def connect_blocking(self, timeout=float('inf')):
# 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
Expand Down Expand Up @@ -903,6 +899,7 @@ def check_version(self, timeout=2, strict=False):

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 = {
Expand Down Expand Up @@ -932,7 +929,7 @@ def check_version(self, timeout=2, strict=False):
]

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
Expand Down