diff --git a/kafka/admin/client.py b/kafka/admin/client.py index 69e643dc7..326ef2541 100644 --- a/kafka/admin/client.py +++ b/kafka/admin/client.py @@ -214,14 +214,20 @@ def __init__(self, **configs): metric_group_prefix='admin', **self.config ) - self._client.check_version(timeout=(self.config['api_version_auto_timeout_ms'] / 1000)) - - # Get auto-discovered version from client if necessary - if self.config['api_version'] is None: - self.config['api_version'] = self._client.config['api_version'] - - self._closed = False - self._refresh_controller_id() + try: + self._client.check_version(timeout=(self.config['api_version_auto_timeout_ms'] / 1000)) + + # Get auto-discovered version from client if necessary + if self.config['api_version'] is None: + self.config['api_version'] = self._client.config['api_version'] + + self._closed = False + self._refresh_controller_id() + except Exception: + self._metrics.close() + self._client.close() # prevent FD leak + self._closed = True + raise log.debug("KafkaAdminClient started.") def close(self):