Skip to content
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
3 changes: 2 additions & 1 deletion kafka/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,8 @@ def check_version(self, node_id=None, timeout=2, strict=False):
if try_node is None:
self._lock.release()
raise Errors.NoBrokersAvailable()
self._maybe_connect(try_node)
if not self._maybe_connect(try_node):
raise Errors.BrokerNotAvailableError()
Comment on lines +914 to +915

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note (non-blocking): This looks correct, and like it should eliminate the chance of a KeyError on the next line.

The _maybe_connect method only returns True if try_node exists in self._conns. I notice there's also locking in that method, indicating there's concurrency and potentially a race condition where the node could be deleted from self._conns with bad timing. I'd be surprised if such a scenario isn't exceedingly rare, and I think this fix is sufficient.

conn = self._conns[try_node]

# We will intentionally cause socket failures
Expand Down