Skip to content

Avoid race condition on client._conns in send() #1772

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
Apr 1, 2019
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
5 changes: 3 additions & 2 deletions kafka/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,15 @@ def send(self, node_id, request, wakeup=True):
Returns:
Future: resolves to Response struct or Error
"""
if not self._can_send_request(node_id):
conn = self._conns.get(node_id)
if not conn or not self._can_send_request(node_id):
self.maybe_connect(node_id, wakeup=wakeup)
return Future().failure(Errors.NodeNotReadyError(node_id))

# conn.send will queue the request internally
# we will need to call send_pending_requests()
# to trigger network I/O
future = self._conns[node_id].send(request, blocking=False)
future = conn.send(request, blocking=False)

# Wakeup signal is useful in case another thread is
# blocked waiting for incoming network traffic while holding
Expand Down