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.
join_group_async() replaced a cached join task with a new JoinGroup whenever the task was done, discarding a successful SyncGroup result that arrived after the previous poll timed out. Reuse a task that succeeded; only replace one that failed.
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
join_group_async()caches the in-flight JoinGroup -> SyncGroup task in_join_taskso that a shortpoll(timeout_ms=N)doesn't send a duplicate JoinGroup. But the reuse check isIf the poll timer expires while SyncGroup is pending and the SyncGroup response arrives before the next poll (the task finishes in the background), the next poll sees
is_doneand starts a brand-new JoinGroup, discarding the successful result. That costs the whole group an extra rebalance round, which is the duplicate JoinGroup the cache was added to prevent.Change
Replace the cached task only when it has failed (
self._join_task.failed()). A task that succeeded is awaited again, which returns its result immediately. A failed task is still replaced as before. This includes a task that failed withKafkaTimeoutErroron a request timeout, which theexcept Errors.KafkaTimeoutErrorbranch can't tell apart from the poll timer expiring.Tests (in
test/consumer/test_coordinator.py, usingMockBroker)test_join_group_async_uses_join_completed_between_polls: SyncGroup is held so the firstjoin_group_async(50)returns False. SyncGroup is then released and the cached task runs to completion before the second call, which must complete the join without another JoinGroup. Without the change a second JoinGroup is sent; nothing is scripted to answer it, so the call fails. With the change the test passes.test_join_group_async_retries_after_join_task_timeout: the first join attempt fails withKafkaTimeoutError, and the next call must start a fresh JoinGroup and succeed. This guards the "reuse only if not failed" part: if the cached task were reused whenever it is set, every later poll would re-await the failed task and return False forever. It passes before and after this PR.Both pass in 20/20 repeated runs.
pytest test --ignore=test/integration: 2732 passed, 1 failed (test/record/test_util.py::test_crc32c[None]; the optionalcrc32cpackage isn't installed locally, unrelated).pylint --errors-onlyon the touched files is clean.This branch is stacked on #3210 (the
need_rejoin()fix), so it also contains that commit until #3210 is merged; only the second commit is new here.