Skip to content

Commit cf1cd10

Browse files
authored
Use client.await_ready() to simplify blocking wait and add timeout to admin client (#2648)
1 parent e4e6fcf commit cf1cd10

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

kafka/admin/client.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from kafka.errors import (
1818
IncompatibleBrokerVersion, KafkaConfigurationError, UnknownTopicOrPartitionError,
1919
UnrecognizedBrokerVersion, IllegalArgumentError)
20+
from kafka.future import Future
2021
from kafka.metrics import MetricConfig, Metrics
2122
from kafka.protocol.admin import (
2223
CreateTopicsRequest, DeleteTopicsRequest, DescribeConfigsRequest, AlterConfigsRequest, CreatePartitionsRequest,
@@ -358,14 +359,11 @@ def _send_request_to_node(self, node_id, request, wakeup=True):
358359
359360
Returns:
360361
A future object that may be polled for status and results.
361-
362-
Raises:
363-
The exception if the message could not be sent.
364362
"""
365-
while not self._client.ready(node_id):
366-
# poll until the connection to broker is ready, otherwise send()
367-
# will fail with NodeNotReadyError
368-
self._client.poll(timeout_ms=200)
363+
try:
364+
self._client.await_ready(node_id)
365+
except Errors.KafkaConnectionError as e:
366+
return Future().failure(e)
369367
return self._client.send(node_id, request, wakeup)
370368

371369
def _send_request_to_controller(self, request):

0 commit comments

Comments
 (0)