Skip to content

fix(binding-kafka): rejoin group when topic metadata is updated after joining - #3294

Merged
jfallows merged 6 commits into
developfrom
fix/3290-group-rejoin-on-new-topic
Nov 16, 2026
Merged

jfallows merged 6 commits into
developfrom
fix/3290-group-rejoin-on-new-topic

Conversation

@jfallows

@jfallows jfallows commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

A group stream can advise updated topic metadata (a new topic added to the member's subscription) at any point after it begins. The client group factory only applied that update in some states, so in others the new topic was stored but never sent in a JoinGroup request and never assigned.

The update is now handled in every state the group client can be in:

  • Before the first join (cluster, describe or join client with the request not yet sent): unchanged, the first JoinGroup carries the stored metadata.
  • While the JoinGroup request is awaiting its response: doJoinGroupRequest is a no-op once the request is in flight, so the member used to sync an assignment built from stale metadata. The metadata version sent in each JoinGroup request is now tracked, and after the SyncGroup response the coordinator rejoins when that version is stale (the same rejoin as for REBALANCE_IN_PROGRESS on sync).
  • After a join has synced (CoordinatorClient, idle): the flush only triggered a heartbeat. It now rejoins with the updated metadata, as JoinGroupClient already does for a flush carrying metadata.
  • Between the join response and the sync response: no immediate rejoin. Rejoining there replaced the active client before the SyncGroup request was sent, so the assignment was never synced and the broker removed the member after the rebalance timeout. The flush is left to the stale-version check after the sync, so the member syncs first and then rejoins. The version that last completed a sync is tracked to tell "idle" from "sync pending".

Symptom this caused in examples/mqtt.kafka.proxy (#3290): a QoS 1 subscription opens three streams on one per-client group (messages, retained, devices). When the streams opened after the group had already joined, only the first topic was assigned. The retained stream then never completed, and live messages stayed buffered, so the subscriber got CONNACK 0 and SUBACK but no messages.

Evidence, from a real single-node apache/kafka:4.1.1 with the example's exact reproduction (after one warm-up publish, which avoids the unrelated CONNACK 142 "session taken over" rejections):

  • Before the change, on the develop head: 8 of 39 runs had at least one QoS 1 subscriber with CONNACK 0 and 0 messages received (11 subscribers in total), while the QoS 0 subscriber on the same topic received ~186. The Kafka coordinator log showed a single JoinGroup, Sync and assignment for those groups, and temporary logging showed the update hitting CoordinatorClient (swallowed) or JoinGroupClient with the request in flight.
  • After the change, on the final tree: 40 runs, 400 QoS 1 subscribers, none stalled; each received 181 to 191 messages. No CONNACK 142 and no DISCONNECT 131 in any run.
  • An intermediate version of this change (unconditional immediate rejoin) still stalled about 1 run in 30 in a third window, which is what the "between join response and sync response" rule above fixes.

Not covered: the DISCONNECT 131 (0x83) variant described in the issue could not be reproduced in any run (0 in 39 before the change, 0 in 40 after), so it is not explained or verified here. Any RESET on the subscribe stream is mapped to DISCONNECT 0x83 by the MQTT server, so a group error would produce it, but that is unconfirmed.

Tests (test-first: each scenario's tests were committed and confirmed failing before its fix):

  • New paired rebalance.new.topic (update after the assignment), rebalance.new.topic.before.join.group.response (update while the join is in flight, ordered with barriers) and rebalance.new.topic.before.member.assignment (update between the join response and the sync) application and network scripts, with spec-level GroupIT cases (application and network).
  • New ClientGroupIT cases for all three scenarios, each confirmed failing on the previous code and passing now.
  • ClientGroupIT, ClientGroupSaslIT, CacheGroupIT, CacheConsumerIT, CacheMergedIT and CacheFetchIT pass with checkstyle enabled (179 tests, 0 failures), and CI is green on the current head.

Fixes #3290

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoXKfATu3qb7FGYa63r

…ated after assignment

Add paired application and network scripts, with spec-level and client
group ITs, for a consumer group whose member advises updated topic
metadata after the first assignment has been received.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXKfATu3qb7FGYa63r
… assignment

A group stream advising updated topic metadata after the member had
joined and synced only triggered a heartbeat, so the new topics were never
sent in a JoinGroup request and never assigned. Rejoin with the updated
metadata, as the join group client already does.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXKfATu3qb7FGYa63r
…ated before the join group response

Add paired application and network scripts, with spec-level and client
group ITs, for a group stream whose member advises updated topic metadata
while its join group request is awaiting a response.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXKfATu3qb7FGYa63r
… was in flight

Topic metadata advised while a join group request was awaiting its
response was stored but never sent, so the member synced an assignment that
lacked the new topics. Track the metadata version sent in each join group
request and rejoin after the sync group response when it is stale.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXKfATu3qb7FGYa63r
@jfallows
jfallows force-pushed the fix/3290-group-rejoin-on-new-topic branch from 0845124 to 85fa621 Compare November 16, 2026 20:45
…ated before the member assignment

Add application scripts, a spec-level ID and a client group IT for a group
stream whose member advises updated topic metadata after the join group
response but before sending its member assignment.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXKfATu3qb7FGYa63r
…ompletes

Rejoining as soon as updated topic metadata arrived replaced the active
client before the sync group request was sent, so the member's assignment was
never synced and the broker removed the member. Rejoin immediately only when
the last join has already synced, otherwise rejoin after the sync group
response.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXKfATu3qb7FGYa63r

Copy link
Copy Markdown
Contributor Author

Final real-broker result on the current head (b3ee36330), using the example's exact reproduction against a single-node apache/kafka:4.1.1 after one warm-up publish:

  • 40 runs, 400 QoS 1 subscribers: none stalled. Each received between 181 and 191 messages, matching the QoS 0 subscriber on the same topic.
  • 0 CONNACK 142 and 0 DISCONNECT 131 in any run.
  • For comparison, before the change on the develop head: 8 of 39 runs had a stalled QoS 1 subscriber (11 subscribers in total).

An earlier version of this branch (unconditional immediate rejoin on a metadata update) still stalled about 1 run in 30. In that case the update arrived between the join response and the sync, the rejoin skipped the SyncGroup, and Kafka removed the member after the rebalance timeout. That case now has its own ClientGroupIT test, and the current head syncs first and then rejoins. The PR description is updated to match.

The DISCONNECT 131 variant from the issue was not reproduced in any run, before or after, so it remains unexplained.


Generated by Claude Code

@jfallows
jfallows merged commit ac0c35f into develop Nov 16, 2026
30 checks passed
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.

mqtt-kafka: some QoS 1 subscribers get SUBACK but never receive messages when they subscribe before publishing starts; some first get DISCONNECT 131

2 participants