@@ -249,8 +249,7 @@ def __init__(self, **configs):
249
249
250
250
# Check Broker Version if not set explicitly
251
251
if self .config ['api_version' ] is None :
252
- check_timeout = self .config ['api_version_auto_timeout_ms' ] / 1000
253
- self .config ['api_version' ] = self .check_version (timeout = check_timeout )
252
+ self .config ['api_version' ] = self .check_version ()
254
253
elif self .config ['api_version' ] in BROKER_API_VERSIONS :
255
254
self ._api_versions = BROKER_API_VERSIONS [self .config ['api_version' ]]
256
255
elif (self .config ['api_version' ] + (0 ,)) in BROKER_API_VERSIONS :
@@ -921,13 +920,16 @@ def get_api_versions(self):
921
920
"""
922
921
return self ._api_versions
923
922
924
- def check_version (self , node_id = None , timeout = 2 , strict = False ):
923
+ def check_version (self , node_id = None , timeout = None , strict = False ):
925
924
"""Attempt to guess the version of a Kafka broker.
926
925
927
- Note: It is possible that this method blocks longer than the
928
- specified timeout. This can happen if the entire cluster
929
- is down and the client enters a bootstrap backoff sleep.
930
- This is only possible if node_id is None.
926
+ Keyword Arguments:
927
+ node_id (str, optional): Broker node id from cluster metadata. If None, attempts
928
+ to connect to any available broker until version is identified.
929
+ Default: None
930
+ timeout (num, optional): Maximum time in seconds to try to check broker version.
931
+ If unable to identify version before timeout, raise error (see below).
932
+ Default: api_version_auto_timeout_ms / 1000
931
933
932
934
Returns: version tuple, i.e. (3, 9), (2, 0), (0, 10, 2) etc
933
935
@@ -937,6 +939,7 @@ def check_version(self, node_id=None, timeout=2, strict=False):
937
939
UnrecognizedBrokerVersion: please file bug if seen!
938
940
AssertionError (if strict=True): please file bug if seen!
939
941
"""
942
+ timeout = timeout or (self .config ['api_version_auto_timeout_ms' ] / 1000 )
940
943
self ._lock .acquire ()
941
944
end = time .time () + timeout
942
945
while time .time () < end :
0 commit comments