Skip to content

Use client.await_ready() to simplify blocking wait and add timeout to admin client #2648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions kafka/admin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from kafka.errors import (
IncompatibleBrokerVersion, KafkaConfigurationError, UnknownTopicOrPartitionError,
UnrecognizedBrokerVersion, IllegalArgumentError)
from kafka.future import Future
from kafka.metrics import MetricConfig, Metrics
from kafka.protocol.admin import (
CreateTopicsRequest, DeleteTopicsRequest, DescribeConfigsRequest, AlterConfigsRequest, CreatePartitionsRequest,
Expand Down Expand Up @@ -358,14 +359,11 @@ def _send_request_to_node(self, node_id, request, wakeup=True):

Returns:
A future object that may be polled for status and results.

Raises:
The exception if the message could not be sent.
"""
while not self._client.ready(node_id):
# poll until the connection to broker is ready, otherwise send()
# will fail with NodeNotReadyError
self._client.poll(timeout_ms=200)
try:
self._client.await_ready(node_id)
except Errors.KafkaConnectionError as e:
return Future().failure(e)
return self._client.send(node_id, request, wakeup)

def _send_request_to_controller(self, request):
Expand Down
Loading