@@ -237,8 +237,7 @@ def __init__(self, **configs):
237
237
238
238
# Check Broker Version if not set explicitly
239
239
if self .config ['api_version' ] is None :
240
- check_timeout = self .config ['api_version_auto_timeout_ms' ] / 1000
241
- self .config ['api_version' ] = self .check_version (timeout = check_timeout )
240
+ self .config ['api_version' ] = self .check_version ()
242
241
243
242
def _init_wakeup_socketpair (self ):
244
243
self ._wake_r , self ._wake_w = socket .socketpair ()
@@ -890,13 +889,16 @@ def get_api_versions(self):
890
889
"""
891
890
return self ._api_versions
892
891
893
- def check_version (self , node_id = None , timeout = 2 , strict = False ):
892
+ def check_version (self , node_id = None , timeout = None , strict = False ):
894
893
"""Attempt to guess the version of a Kafka broker.
895
894
896
- Note: It is possible that this method blocks longer than the
897
- specified timeout. This can happen if the entire cluster
898
- is down and the client enters a bootstrap backoff sleep.
899
- This is only possible if node_id is None.
895
+ Keyword Arguments:
896
+ node_id (str, optional): Broker node id from cluster metadata. If None, attempts
897
+ to connect to any available broker until version is identified.
898
+ Default: None
899
+ timeout (num, optional): Maximum time in seconds to try to check broker version.
900
+ If unable to identify version before timeout, raise error (see below).
901
+ Default: api_version_auto_timeout_ms / 1000
900
902
901
903
Returns: version tuple, i.e. (0, 10), (0, 9), (0, 8, 2), ...
902
904
@@ -906,6 +908,7 @@ def check_version(self, node_id=None, timeout=2, strict=False):
906
908
UnrecognizedBrokerVersion: please file bug if seen!
907
909
AssertionError (if strict=True): please file bug if seen!
908
910
"""
911
+ timeout = timeout or (self .config ['api_version_auto_timeout_ms' ] / 1000 )
909
912
self ._lock .acquire ()
910
913
end = time .time () + timeout
911
914
while time .time () < end :
0 commit comments