From 4254119933ffaf81e24f1b10fbccbf120a54326c Mon Sep 17 00:00:00 2001 From: "Augusto F. Hack" Date: Thu, 14 Jan 2021 17:07:21 +0100 Subject: [PATCH] bugfix: fix infinite loop Calling `_send_request_to_node` with the result of `least_loaded_node` results in an infinite loop if the metadata is out-dated and `least_loaded_node` return the `node_id` of a broker that was removed from the cluster. The method `_send_request_to_least_loaded_node` handles this race and fixes the infinite loop. --- karapace/kafka_rest_apis/admin.py | 4 ++-- requirements-dev.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/karapace/kafka_rest_apis/admin.py b/karapace/kafka_rest_apis/admin.py index c1e4359b5..c03dc0902 100644 --- a/karapace/kafka_rest_apis/admin.py +++ b/karapace/kafka_rest_apis/admin.py @@ -45,7 +45,7 @@ def cluster_metadata(self, topics: List[str] = None, retries: int = 0) -> dict: "Kafka Admin interface cannot determine the controller using MetadataRequest_v{}.".format(metadata_version) ) request = MetadataRequest[1](topics=topics) - future = self._send_request_to_node(self._client.least_loaded_node(), request) + future = self._send_request_to_least_loaded_node(request) try: self._wait_for_futures([future]) except Cancelled: @@ -94,7 +94,7 @@ def make_offsets_request(self, topic: str, partition_id: int, timestamp: int) -> else: request = OffsetRequest[2](-1, 1, list(six.iteritems({topic: [(partition_id, timestamp)]}))) - future = self._send_request_to_node(self._client.least_loaded_node(), request) + future = self._send_request_to_least_loaded_node(request) return future def get_offsets(self, topic: str, partition_id: int) -> dict: diff --git a/requirements-dev.txt b/requirements-dev.txt index 4a6bb535f..d019f6d90 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ git+https://github.com/aiven/avro.git@skip-namespace-validation#subdirectory=lang/py3/ -git+git://github.com/aiven/kafka-python.git@346c01e4eec6bdcccc99ca613b79020f3be35eb7 +git+git://github.com/aiven/kafka-python.git@b9f2f78377d56392f61cba8856dc6c02ae841b79 yapf==0.30.0 aiohttp-socks==0.5.5 pylint==2.4.4