Repository navigation
Conversation
When a leader rejoins because of a metadata change, performing the assignment refreshes its assignment snapshot and clears the trigger. If SyncGroup was still pending when poll timed out, the next poll saw need_rejoin() == False and returned without awaiting the in-flight join, leaving the consumer in REBALANCING on its old assignment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What goes wrong
A group leader that rejoins because topic metadata changed (e.g. a subscribed topic gained partitions) can get stuck in
REBALANCINGon its old assignment when the rejoin spans more than onepoll():rejoin_neededis False. The partition count changes, soConsumerCoordinator.need_rejoin()returns True through_assignment_snapshot != _metadata_snapshot.poll(timeout_ms=small)starts the join. JoinGroup returns, the leader runs_perform_assignment(), which sets_assignment_snapshot = _metadata_snapshot. SyncGroup is still pending when the poll timer expires, sojoin_group_async()returns False and leaves_join_taskin flight (as intended).rejoin_neededstill False), soneed_rejoin()is False.ConsumerCoordinator.poll()skipsensure_active_group()andjoin_group_async()exits itswhile self.need_rejoin()loop immediately. The finished SyncGroup is never collected:_on_join_completedoes not run, the state staysREBALANCING, heartbeats stay disabled and the new partitions are never assigned.Why
need_rejoin()only reports why a rebalance is needed, not that one is already underway. The Java client avoids this withrejoinNeededOrPending()(rejoinNeeded || joinFuture != null).Change
BaseCoordinator.need_rejoin()returnsself.rejoin_needed or self.rejoining.rejoiningis set when a rebalance attempt starts (after_on_join_prepare) and cleared when it completes, so it is exactly the "pending" half ofrejoinNeededOrPending().Test
test_join_group_async_collects_pending_sync_after_leader_assignmentintest/consumer/test_coordinator.pyusesMockBroker: a stable leader sees its topic grow from 1 to 2 partitions, JoinGroup answers immediately, SyncGroup is held on a future, the firstjoin_group_async(50)returns False, then SyncGroup is released and the second call must complete the join. Without the change the second call returns True with the state stillREBALANCING:With the change it passes (20/20 repeated runs).
pytest test --ignore=test/integration: 2730 passed, 1 failed (test/record/test_util.py::test_crc32c[None], optionalcrc32cpackage not installed locally, unrelated).pylint --errors-onlyon the touched files is clean.A related problem in the same function (a join task that completes between polls is discarded) is addressed separately in another PR.