Skip to content

Fix #1083: Deal with brokers that disappear, reappear with different IP address #1085

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

Closed
Closed
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
13 changes: 12 additions & 1 deletion kafka/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,19 @@ def _conn_state_change(self, node_id, conn):

def _maybe_connect(self, node_id):
"""Idempotent non-blocking connection attempt to the given node id."""
broker = self.cluster.broker_metadata(node_id)

# If broker metadata indicates that a node's host/port has changed, remove it
if node_id in self._conns and broker is not None:
conn = self._conns[node_id]
host, _, __ = get_ip_port_afi(broker.host)
if conn.host != host or conn.port != broker.port:
log.debug("Closing connection to decommissioned node %s at %s:%s",
node_id, conn.host, conn.port)
conn.close()
self._conns.pop(node_id)

if node_id not in self._conns:
broker = self.cluster.broker_metadata(node_id)
assert broker, 'Broker id %s not in current metadata' % node_id

log.debug("Initiating connection to node %s at %s:%s",
Expand Down