Skip to content

Commit 39ebe1d

Browse files
authored
Improve connection handling when bootstrap list is invalid (#1507)
* only perform single dns lookup for connect_blocking() * fix blocking timeout in check_version()
1 parent ee26c3f commit 39ebe1d

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

kafka/conn.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,7 @@ def connect_blocking(self, timeout=float('inf')):
292292
# First attempt to perform dns lookup
293293
# note that the underlying interface, socket.getaddrinfo,
294294
# has no explicit timeout so we may exceed the user-specified timeout
295-
while time.time() < timeout:
296-
if self._dns_lookup():
297-
break
298-
else:
299-
return False
295+
self._dns_lookup()
300296

301297
# Loop once over all returned dns entries
302298
selector = None
@@ -903,6 +899,7 @@ def check_version(self, timeout=2, strict=False):
903899
904900
Returns: version tuple, i.e. (0, 10), (0, 9), (0, 8, 2), ...
905901
"""
902+
timeout_at = time.time() + timeout
906903
log.info('Probing node %s broker version', self.node_id)
907904
# Monkeypatch some connection configurations to avoid timeouts
908905
override_config = {
@@ -932,7 +929,7 @@ def check_version(self, timeout=2, strict=False):
932929
]
933930

934931
for version, request in test_cases:
935-
if not self.connect_blocking(timeout):
932+
if not self.connect_blocking(timeout_at - time.time()):
936933
raise Errors.NodeNotReadyError()
937934
f = self.send(request)
938935
# HACK: sleeping to wait for socket to send bytes

0 commit comments

Comments
 (0)