Skip to content

Reset metadata backoff after a broker connection recovers - #3197

Open
narayana006 wants to merge 2 commits into
dpkp:masterfrom
narayana006:candidate/metadata-backoff-recovery
Open

narayana006 wants to merge 2 commits into
dpkp:masterfrom
narayana006:candidate/metadata-backoff-recovery

Conversation

@narayana006

@narayana006 narayana006 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

When metadata refresh finds no available broker, it enters exponential backoff. A later successful broker connection used to leave that metadata backoff intact, delaying even a requested refresh.

The connection manager now notifies ClusterMetadata.on_connection_ready() after successful initialization. ClusterMetadata resets its own retry state, keeping the metadata backoff key inside kafka/cluster.py. The existing bootstrap opt-out remains intact, failed connections retain their backoff, and unrelated brokers retain their retry delays.

Regression tests check metadata TTL, bootstrap and failure controls. Protocol round trips against MockCluster verify that both selector and asyncio backends obtain changed partition metadata after reconnection without waiting for the previous exponential backoff.

Refs #3188.

Validation on macOS / Python 3.11.15:

  • Three original regression cases fail before the recovery fix; two controls pass.
  • Current networking, cluster metadata and consumer-fetch selection: 565 passed.
  • Repository-wide make lint and git diff --check pass.

The live Docker/broker-restart and FENCED_LEADER_EPOCH scenario, full test suite and broker/Python CI matrix were not run locally; these tests isolate the metadata-backoff recovery path.

@dpkp

dpkp commented Nov 20, 2026

Copy link
Copy Markdown
Owner

My concern here is that it leaks the 'metadata' backoff key out of kafka/cluster.py / ClusterMetadata. I would like to keep this encapsulation, so I'll think about how we might need to improve the interface between net layer / bootstrap and metadata.

@narayana006

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. Updated this PR in a65989e to keep the metadata backoff key inside ClusterMetadata.

The connection manager now calls cluster.on_connection_ready() after successful initialization. ClusterMetadata handles resetting its own retry state. The existing bootstrap opt-out and failed-connection behavior are preserved.

Local validation: 565 networking, cluster metadata and consumer-fetch tests pass, including recovery round trips on both selector and asyncio backends; repository-wide make lint and git diff --check pass. Live broker-restart/FENCED_LEADER_EPOCH testing and the full Python/broker matrix were not run locally.

Would this connection-ready notification be a suitable interface, or would you prefer a different handoff between the manager and metadata?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants